Search in sources :

Example 1 with MPartitionColumnPrivilege

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;
}
Also used : Query(javax.jdo.Query) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)

Example 2 with MPartitionColumnPrivilege

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;
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) ArrayList(java.util.ArrayList) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) ReplicationMetricList(org.apache.hadoop.hive.metastore.api.ReplicationMetricList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList) List(java.util.List) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)

Example 3 with MPartitionColumnPrivilege

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;
}
Also used : MFieldSchema(org.apache.hadoop.hive.metastore.model.MFieldSchema) ArrayList(java.util.ArrayList) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)

Example 4 with MPartitionColumnPrivilege

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;
}
Also used : MPartition(org.apache.hadoop.hive.metastore.model.MPartition) Partition(org.apache.hadoop.hive.metastore.api.Partition) MFieldSchema(org.apache.hadoop.hive.metastore.model.MFieldSchema) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint) MTable(org.apache.hadoop.hive.metastore.model.MTable) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) PartitionSpecProxy(org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 5 with MPartitionColumnPrivilege

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));
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) ReplicationMetricList(org.apache.hadoop.hive.metastore.api.ReplicationMetricList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList) List(java.util.List) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)

Aggregations

MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)17 ArrayList (java.util.ArrayList)12 MPartitionPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)8 MTableColumnPrivilege (org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)8 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)7 MTable (org.apache.hadoop.hive.metastore.model.MTable)7 MTablePrivilege (org.apache.hadoop.hive.metastore.model.MTablePrivilege)7 Query (javax.jdo.Query)6 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)6 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)6 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)6 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)6 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)5 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)5 ReplicationMetricList (org.apache.hadoop.hive.metastore.api.ReplicationMetricList)5 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)5 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)5