if(SessionState.get().isAuthorizationModeV2()){
return showGrantsV2(showGrantDesc);
}
PrincipalDesc principalDesc = showGrantDesc.getPrincipalDesc();
PrivilegeObjectDesc hiveObjectDesc = showGrantDesc.getHiveObj();
String principalName = principalDesc == null ? null : principalDesc.getName();
PrincipalType type = principalDesc == null ? null : principalDesc.getType();
List<HiveObjectPrivilege> privs = new ArrayList<HiveObjectPrivilege>();
try {
if (hiveObjectDesc == null) {
privs.addAll(db.showPrivilegeGrant(HiveObjectType.GLOBAL, principalName, type,
null, null, null, null));
} else if (hiveObjectDesc != null && hiveObjectDesc.getObject() == null) {
privs.addAll(db.showPrivilegeGrant(null, principalName, type, null, null, null, null));
} else {
String obj = hiveObjectDesc.getObject();
boolean notFound = true;
String dbName = null;
String tableName = null;
Table tableObj = null;
Database dbObj = null;
if (hiveObjectDesc.getTable()) {
String[] dbTab = obj.split("\\.");
if (dbTab.length == 2) {
dbName = dbTab[0];
tableName = dbTab[1];
} else {
dbName = SessionState.get().getCurrentDatabase();
tableName = obj;
}
dbObj = db.getDatabase(dbName);
tableObj = db.getTable(dbName, tableName);
notFound = (dbObj == null || tableObj == null);
} else {
dbName = hiveObjectDesc.getObject();
dbObj = db.getDatabase(dbName);
notFound = (dbObj == null);
}
if (notFound) {
throw new HiveException(obj + " can not be found");
}
String partName = null;
List<String> partValues = null;
if (hiveObjectDesc.getPartSpec() != null) {
partName = Warehouse
.makePartName(hiveObjectDesc.getPartSpec(), false);
partValues = Warehouse.getPartValuesFromPartName(partName);
}
if (!hiveObjectDesc.getTable()) {
// show database level privileges
privs.addAll(db.showPrivilegeGrant(HiveObjectType.DATABASE,
principalName, type, dbName, null, null, null));
} else {
if (showGrantDesc.getColumns() != null) {
// show column level privileges
for (String columnName : showGrantDesc.getColumns()) {
privs.addAll(db.showPrivilegeGrant(
HiveObjectType.COLUMN, principalName,
type, dbName, tableName, partValues,
columnName));
}
} else if (hiveObjectDesc.getPartSpec() != null) {
// show partition level privileges
privs.addAll(db.showPrivilegeGrant(
HiveObjectType.PARTITION, principalName, type,
dbName, tableName, partValues, null));
} else {