Search in sources :

Example 6 with MPartitionPrivilege

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

the class ObjectStore method addPartition.

@Override
public boolean addPartition(Partition part) throws InvalidObjectException, MetaException {
    boolean success = false;
    boolean commited = false;
    try {
        MTable table = this.getMTable(part.getDbName(), part.getTableName());
        List<MTablePrivilege> tabGrants = null;
        List<MTableColumnPrivilege> tabColumnGrants = null;
        if ("TRUE".equalsIgnoreCase(table.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))) {
            tabGrants = this.listAllTableGrants(part.getDbName(), part.getTableName());
            tabColumnGrants = this.listTableAllColumnGrants(part.getDbName(), part.getTableName());
        }
        openTransaction();
        MPartition mpart = convertToMPart(part, true);
        pm.makePersistent(mpart);
        int now = (int) (System.currentTimeMillis() / 1000);
        List<Object> toPersist = new ArrayList<Object>();
        if (tabGrants != null) {
            for (MTablePrivilege tab : tabGrants) {
                MPartitionPrivilege partGrant = new MPartitionPrivilege(tab.getPrincipalName(), tab.getPrincipalType(), mpart, tab.getPrivilege(), now, tab.getGrantor(), tab.getGrantorType(), tab.getGrantOption());
                toPersist.add(partGrant);
            }
        }
        if (tabColumnGrants != null) {
            for (MTableColumnPrivilege col : tabColumnGrants) {
                MPartitionColumnPrivilege partColumn = new MPartitionColumnPrivilege(col.getPrincipalName(), col.getPrincipalType(), mpart, col.getColumnName(), col.getPrivilege(), now, col.getGrantor(), col.getGrantorType(), col.getGrantOption());
                toPersist.add(partColumn);
            }
            if (toPersist.size() > 0) {
                pm.makePersistentAll(toPersist);
            }
        }
        commited = commitTransaction();
        success = true;
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : ArrayList(java.util.ArrayList) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) 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) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 7 with MPartitionPrivilege

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

the class ObjectStore method listTableAllPartitionGrants.

@SuppressWarnings("unchecked")
public List<MPartitionPrivilege> listTableAllPartitionGrants(String dbName, String tableName) {
    tableName = HiveStringUtils.normalizeIdentifier(tableName);
    dbName = HiveStringUtils.normalizeIdentifier(dbName);
    boolean success = false;
    Query query = null;
    List<MPartitionPrivilege> mSecurityTabPartList = new ArrayList<MPartitionPrivilege>();
    try {
        LOG.debug("Executing listTableAllPartitionGrants");
        openTransaction();
        String queryStr = "partition.table.tableName == t1 && partition.table.database.name == t2";
        query = pm.newQuery(MPartitionPrivilege.class, queryStr);
        query.declareParameters("java.lang.String t1, java.lang.String t2");
        List<MPartitionPrivilege> mPrivs = (List<MPartitionPrivilege>) query.executeWithArray(tableName, dbName);
        pm.retrieveAll(mPrivs);
        success = commitTransaction();
        mSecurityTabPartList.addAll(mPrivs);
        LOG.debug("Done retrieving all objects for listTableAllPartitionGrants");
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
    return mSecurityTabPartList;
}
Also used : Query(javax.jdo.Query) ArrayList(java.util.ArrayList) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 8 with MPartitionPrivilege

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

the class ObjectStore method listPrincipalAllPartitionGrants.

@SuppressWarnings("unchecked")
private List<MPartitionPrivilege> listPrincipalAllPartitionGrants(String principalName, PrincipalType principalType, QueryWrapper queryWrapper) {
    boolean success = false;
    List<MPartitionPrivilege> mSecurityTabPartList = null;
    try {
        openTransaction();
        LOG.debug("Executing listPrincipalAllPartitionGrants");
        Query query = queryWrapper.query = pm.newQuery(MPartitionPrivilege.class, "principalName == t1 && principalType == t2");
        query.declareParameters("java.lang.String t1, java.lang.String t2");
        mSecurityTabPartList = (List<MPartitionPrivilege>) query.execute(principalName, principalType.toString());
        pm.retrieveAll(mSecurityTabPartList);
        success = commitTransaction();
        LOG.debug("Done retrieving all objects for listPrincipalAllPartitionGrants");
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return mSecurityTabPartList;
}
Also used : Query(javax.jdo.Query) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)

Example 9 with MPartitionPrivilege

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

the class ObjectStore method addPartitions.

@Override
public boolean addPartitions(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(dbName, tblName);
        if ("TRUE".equalsIgnoreCase(table.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))) {
            tabGrants = this.listAllTableGrants(dbName, tblName);
            tabColumnGrants = this.listTableAllColumnGrants(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);
        while (iterator.hasNext()) {
            Partition part = iterator.next();
            if (isValidPartition(part, ifNotExists)) {
                MPartition mpart = convertToMPart(part, 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()));
                    }
                }
                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()));
                    }
                }
            }
        }
        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) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) 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 10 with MPartitionPrivilege

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

the class ObjectStore method listPartitionGrantsAll.

@Override
public List<HiveObjectPrivilege> listPartitionGrantsAll(String dbName, String tableName, String partitionName) {
    boolean success = false;
    Query query = null;
    try {
        openTransaction();
        LOG.debug("Executing listPrincipalPartitionGrantsAll");
        query = pm.newQuery(MPartitionPrivilege.class, "partition.table.tableName == t3 && partition.table.database.name == t4 && " + "partition.partitionName == t5");
        query.declareParameters("java.lang.String t3, java.lang.String t4, java.lang.String t5");
        List<MPartitionPrivilege> mSecurityTabPartList = (List<MPartitionPrivilege>) query.executeWithArray(tableName, dbName, partitionName);
        LOG.debug("Done executing query for listPrincipalPartitionGrantsAll");
        pm.retrieveAll(mSecurityTabPartList);
        List<HiveObjectPrivilege> result = convertPartition(mSecurityTabPartList);
        success = commitTransaction();
        LOG.debug("Done retrieving all objects for listPrincipalPartitionGrantsAll");
        return result;
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Query(javax.jdo.Query) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

MPartitionPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)16 ArrayList (java.util.ArrayList)11 MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)8 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)7 MTable (org.apache.hadoop.hive.metastore.model.MTable)7 MTableColumnPrivilege (org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)7 MTablePrivilege (org.apache.hadoop.hive.metastore.model.MTablePrivilege)7 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 Query (javax.jdo.Query)5 MPartition (org.apache.hadoop.hive.metastore.model.MPartition)5 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)5 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)4 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)3 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)3 MDBPrivilege (org.apache.hadoop.hive.metastore.model.MDBPrivilege)3 MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)3 MGlobalPrivilege (org.apache.hadoop.hive.metastore.model.MGlobalPrivilege)3