Search in sources :

Example 1 with MTableColumnPrivilege

use of org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege in project hive by apache.

the class ObjectStore method listPrincipalAllTableColumnGrants.

@SuppressWarnings("unchecked")
private List<MTableColumnPrivilege> listPrincipalAllTableColumnGrants(String principalName, PrincipalType principalType, QueryWrapper queryWrapper) {
    boolean success = false;
    List<MTableColumnPrivilege> mSecurityColumnList = null;
    try {
        LOG.debug("Executing listPrincipalAllTableColumnGrants");
        openTransaction();
        Query query = queryWrapper.query = pm.newQuery(MTableColumnPrivilege.class, "principalName == t1 && principalType == t2");
        query.declareParameters("java.lang.String t1, java.lang.String t2");
        mSecurityColumnList = (List<MTableColumnPrivilege>) 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) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)

Example 2 with MTableColumnPrivilege

use of org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege in project hive by apache.

the class ObjectStore method listPrincipalTableColumnGrants.

@Override
public List<HiveObjectPrivilege> listPrincipalTableColumnGrants(String principalName, PrincipalType principalType, String catName, String dbName, String tableName, String columnName) {
    List<MTableColumnPrivilege> mTableCols = listPrincipalMTableColumnGrants(principalName, principalType, catName, dbName, tableName, columnName);
    if (mTableCols.isEmpty()) {
        return Collections.emptyList();
    }
    List<HiveObjectPrivilege> result = new ArrayList<>();
    for (int i = 0; i < mTableCols.size(); i++) {
        MTableColumnPrivilege sCol = mTableCols.get(i);
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.COLUMN, dbName, tableName, null, sCol.getColumnName());
        objectRef.setCatName(catName);
        HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef, sCol.getPrincipalName(), principalType, new PrivilegeGrantInfo(sCol.getPrivilege(), sCol.getCreateTime(), sCol.getGrantor(), PrincipalType.valueOf(sCol.getGrantorType()), sCol.getGrantOption()), sCol.getAuthorizer());
        result.add(secObj);
    }
    return result;
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege) 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)

Example 3 with MTableColumnPrivilege

use of org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege in project hive by apache.

the class ObjectStore method listPrincipalAllTableColumnGrants.

private List<MTableColumnPrivilege> listPrincipalAllTableColumnGrants(String principalName, PrincipalType principalType) throws Exception {
    LOG.debug("Executing listPrincipalAllTableColumnGrants");
    Preconditions.checkState(this.currentTransaction.isActive());
    try (Query query = pm.newQuery(MTableColumnPrivilege.class, "principalName == t1 && principalType == t2")) {
        query.declareParameters("java.lang.String t1, java.lang.String t2");
        final List<MTableColumnPrivilege> mSecurityColumnList = (List<MTableColumnPrivilege>) 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) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)

Example 4 with MTableColumnPrivilege

use of org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege 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 MTableColumnPrivilege

use of org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege in project hive by apache.

the class ObjectStore method addPartitions.

@Override
public boolean addPartitions(String catName, String dbName, String tblName, List<Partition> parts) 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);
        }
        List<Object> toPersist = new ArrayList<>();
        for (Partition part : parts) {
            if (!part.getTableName().equals(tblName) || !part.getDbName().equals(dbName)) {
                throw new MetaException("Partition does not belong to target table " + dbName + "." + tblName + ": " + part);
            }
            MPartition mpart = convertToMPart(part, table, true);
            toPersist.add(mpart);
            int now = (int) (System.currentTimeMillis() / 1000);
            if (tabGrants != null) {
                for (MTablePrivilege tab : tabGrants) {
                    toPersist.add(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) {
                    toPersist.add(new MPartitionColumnPrivilege(col.getPrincipalName(), col.getPrincipalType(), mpart, col.getColumnName(), col.getPrivilege(), now, col.getGrantor(), col.getGrantorType(), col.getGrantOption(), col.getAuthorizer()));
                }
            }
        }
        if (CollectionUtils.isNotEmpty(toPersist)) {
            pm.makePersistentAll(toPersist);
            pm.flush();
        }
        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) ArrayList(java.util.ArrayList) 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) 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)

Aggregations

MTableColumnPrivilege (org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)16 ArrayList (java.util.ArrayList)11 MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)8 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)7 MPartitionPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)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 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)5 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)4 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)4 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)4