throw new HiveException(
"For user-level privileges, column sets should be null. columns="
+ privileges.get(idx).getColumns().toString());
}
privBag.addToPrivileges(new HiveObjectPrivilege(new HiveObjectRef(
HiveObjectType.GLOBAL, null, null, null, null), null, null,
new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType,
grantOption)));
}
} else {
org.apache.hadoop.hive.metastore.api.Partition partObj = null;
List<String> partValues = null;
if (tableObj != null) {
if ((!tableObj.isPartitioned())
&& privSubjectDesc.getPartSpec() != null) {
throw new HiveException(
"Table is not partitioned, but partition name is present: partSpec="
+ privSubjectDesc.getPartSpec().toString());
}
if (privSubjectDesc.getPartSpec() != null) {
partObj = db.getPartition(tableObj, privSubjectDesc.getPartSpec(),
false).getTPartition();
partValues = partObj.getValues();
}
}
for (PrivilegeDesc privDesc : privileges) {
List<String> columns = privDesc.getColumns();
Privilege priv = privDesc.getPrivilege();
if (columns != null && columns.size() > 0) {
if (!priv.supportColumnLevel()) {
throw new HiveException(priv.toString()
+ " does not support column level.");
}
if (privSubjectDesc == null || tableName == null) {
throw new HiveException(
"For user-level/database-level privileges, column sets should be null. columns="
+ columns);
}
for (int i = 0; i < columns.size(); i++) {
privBag.addToPrivileges(new HiveObjectPrivilege(
new HiveObjectRef(HiveObjectType.COLUMN, dbName, tableName,
partValues, columns.get(i)), null, null, new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType, grantOption)));
}
} else {
if (privSubjectDesc.getTable()) {
if (privSubjectDesc.getPartSpec() != null) {
privBag.addToPrivileges(new HiveObjectPrivilege(
new HiveObjectRef(HiveObjectType.PARTITION, dbName,
tableName, partValues, null), null, null, new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType, grantOption)));
} else {
privBag
.addToPrivileges(new HiveObjectPrivilege(
new HiveObjectRef(HiveObjectType.TABLE, dbName,
tableName, null, null), null, null, new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType, grantOption)));
}
} else {
privBag.addToPrivileges(new HiveObjectPrivilege(
new HiveObjectRef(HiveObjectType.DATABASE, dbName, null,
null, null), null, null, new PrivilegeGrantInfo(priv.toString(), 0, grantor, grantorType, grantOption)));
}
}
}
}
for (PrincipalDesc principal : principals) {
for (int i = 0; i < privBag.getPrivileges().size(); i++) {
HiveObjectPrivilege objPrivs = privBag.getPrivileges().get(i);
objPrivs.setPrincipalName(principal.getName());
objPrivs.setPrincipalType(principal.getType());
}
if (isGrant) {
db.grantPrivileges(privBag);
} else {
db.revokePrivileges(privBag);