use of org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege in project hive by apache.
the class ObjectStore method listPrincipalAllPartitionColumnGrants.
@SuppressWarnings("unchecked")
private List<MPartitionColumnPrivilege> listPrincipalAllPartitionColumnGrants(String principalName, PrincipalType principalType, QueryWrapper queryWrapper) {
boolean success = false;
List<MPartitionColumnPrivilege> mSecurityColumnList = null;
try {
LOG.debug("Executing listPrincipalAllTableColumnGrants");
openTransaction();
Query query = queryWrapper.query = pm.newQuery(MPartitionColumnPrivilege.class, "principalName == t1 && principalType == t2");
query.declareParameters("java.lang.String t1, java.lang.String t2");
mSecurityColumnList = (List<MPartitionColumnPrivilege>) query.execute(principalName, principalType.toString());
pm.retrieveAll(mSecurityColumnList);
success = commitTransaction();
LOG.debug("Done retrieving all objects for listPrincipalAllTableColumnGrants");
} finally {
if (!success) {
rollbackTransaction();
}
}
return mSecurityColumnList;
}
use of org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege in project hive by apache.
the class ObjectStore method listTableAllPartitionColumnGrants.
private List<MPartitionColumnPrivilege> listTableAllPartitionColumnGrants(String catName, String dbName, String tableName) {
boolean success = false;
Query query = null;
tableName = normalizeIdentifier(tableName);
dbName = normalizeIdentifier(dbName);
catName = normalizeIdentifier(catName);
List<MPartitionColumnPrivilege> mSecurityColList = new ArrayList<>();
try {
LOG.debug("Executing listTableAllPartitionColumnGrants");
openTransaction();
String queryStr = "partition.table.tableName == t1 && partition.table.database.name == t2 " + "&& partition.table.database.catalogName == t3";
query = pm.newQuery(MPartitionColumnPrivilege.class, queryStr);
query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
List<MPartitionColumnPrivilege> mPrivs = (List<MPartitionColumnPrivilege>) query.executeWithArray(tableName, dbName, catName);
pm.retrieveAll(mPrivs);
success = commitTransaction();
mSecurityColList.addAll(mPrivs);
LOG.debug("Done retrieving all objects for listTableAllPartitionColumnGrants");
} finally {
rollbackAndCleanup(success, query);
}
return mSecurityColList;
}
use of org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege in project hive by apache.
the class ObjectStore method dropPartitionCommon.
/**
* Drop an MPartition and cascade deletes (e.g., delete partition privilege grants,
* drop the storage descriptor cleanly, etc.)
*/
private boolean dropPartitionCommon(MPartition part) throws MetaException, InvalidObjectException, InvalidInputException {
boolean success = false;
try {
openTransaction();
if (part != null) {
List<MFieldSchema> schemas = part.getTable().getPartitionKeys();
List<String> colNames = new ArrayList<>();
for (MFieldSchema col : schemas) {
colNames.add(col.getName());
}
String partName = FileUtils.makePartName(colNames, part.getValues());
List<MPartitionPrivilege> partGrants = listPartitionGrants(part.getTable().getDatabase().getCatalogName(), part.getTable().getDatabase().getName(), part.getTable().getTableName(), Lists.newArrayList(partName));
if (CollectionUtils.isNotEmpty(partGrants)) {
pm.deletePersistentAll(partGrants);
}
List<MPartitionColumnPrivilege> partColumnGrants = listPartitionAllColumnGrants(part.getTable().getDatabase().getCatalogName(), part.getTable().getDatabase().getName(), part.getTable().getTableName(), Lists.newArrayList(partName));
if (CollectionUtils.isNotEmpty(partColumnGrants)) {
pm.deletePersistentAll(partColumnGrants);
}
String catName = part.getTable().getDatabase().getCatalogName();
String dbName = part.getTable().getDatabase().getName();
String tableName = part.getTable().getTableName();
// delete partition level column stats if it exists
try {
deletePartitionColumnStatistics(catName, dbName, tableName, partName, part.getValues(), null, null);
} catch (NoSuchObjectException e) {
LOG.info("No column statistics records found to delete");
}
preDropStorageDescriptor(part.getSd());
pm.deletePersistent(part);
}
success = commitTransaction();
} finally {
if (!success) {
rollbackTransaction();
}
}
return success;
}
use of org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege in project hive by apache.
the class ObjectStore method addPartitions.
@Override
public boolean addPartitions(String catName, String dbName, String tblName, PartitionSpecProxy partitionSpec, boolean ifNotExists) throws InvalidObjectException, MetaException {
boolean success = false;
openTransaction();
try {
List<MTablePrivilege> tabGrants = null;
List<MTableColumnPrivilege> tabColumnGrants = null;
MTable table = this.getMTable(catName, dbName, tblName);
if ("TRUE".equalsIgnoreCase(table.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))) {
tabGrants = this.listAllTableGrants(catName, dbName, tblName);
tabColumnGrants = this.listTableAllColumnGrants(catName, dbName, tblName);
}
if (!partitionSpec.getTableName().equals(tblName) || !partitionSpec.getDbName().equals(dbName)) {
throw new MetaException("Partition does not belong to target table " + dbName + "." + tblName + ": " + partitionSpec);
}
PartitionSpecProxy.PartitionIterator iterator = partitionSpec.getPartitionIterator();
int now = (int) (System.currentTimeMillis() / 1000);
List<FieldSchema> partitionKeys = convertToFieldSchemas(table.getPartitionKeys());
while (iterator.hasNext()) {
Partition part = iterator.next();
if (isValidPartition(part, partitionKeys, ifNotExists)) {
MPartition mpart = convertToMPart(part, table, true);
pm.makePersistent(mpart);
if (tabGrants != null) {
for (MTablePrivilege tab : tabGrants) {
pm.makePersistent(new MPartitionPrivilege(tab.getPrincipalName(), tab.getPrincipalType(), mpart, tab.getPrivilege(), now, tab.getGrantor(), tab.getGrantorType(), tab.getGrantOption(), tab.getAuthorizer()));
}
}
if (tabColumnGrants != null) {
for (MTableColumnPrivilege col : tabColumnGrants) {
pm.makePersistent(new MPartitionColumnPrivilege(col.getPrincipalName(), col.getPrincipalType(), mpart, col.getColumnName(), col.getPrivilege(), now, col.getGrantor(), col.getGrantorType(), col.getGrantOption(), col.getAuthorizer()));
}
}
}
}
success = commitTransaction();
} finally {
if (!success) {
rollbackTransaction();
}
}
return success;
}
use of org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege in project hive by apache.
the class ObjectStore method listPrincipalAllPartitionColumnGrants.
private List<MPartitionColumnPrivilege> listPrincipalAllPartitionColumnGrants(String principalName, PrincipalType principalType) throws Exception {
LOG.debug("Executing listPrincipalAllTableColumnGrants");
Preconditions.checkState(this.currentTransaction.isActive());
try (Query query = pm.newQuery(MPartitionColumnPrivilege.class, "principalName == t1 && principalType == t2")) {
query.declareParameters("java.lang.String t1, java.lang.String t2");
final List<MPartitionColumnPrivilege> mSecurityColumnList = (List<MPartitionColumnPrivilege>) query.execute(principalName, principalType.toString());
pm.retrieveAll(mSecurityColumnList);
LOG.debug("Done retrieving all objects for listPrincipalAllTableColumnGrants");
return Collections.unmodifiableList(new ArrayList<>(mSecurityColumnList));
}
}
Aggregations