Search in sources :

Example 11 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 {
        rollbackAndCleanup(success, query);
    }
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Query(javax.jdo.Query) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with MPartitionPrivilege

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

the class ObjectStore method listPrincipalPartitionGrantsAll.

@Override
public List<HiveObjectPrivilege> listPrincipalPartitionGrantsAll(String principalName, PrincipalType principalType) {
    boolean success = false;
    Query query = null;
    try {
        openTransaction();
        LOG.debug("Executing listPrincipalPartitionGrantsAll");
        List<MPartitionPrivilege> mSecurityTabPartList;
        if (principalName != null && principalType != null) {
            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());
        } else {
            query = pm.newQuery(MPartitionPrivilege.class);
            mSecurityTabPartList = (List<MPartitionPrivilege>) query.execute();
        }
        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 {
        rollbackAndCleanup(success, query);
    }
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Query(javax.jdo.Query) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)

Example 13 with MPartitionPrivilege

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

the class ObjectStore method grantPrivileges.

@Override
public boolean grantPrivileges(PrivilegeBag privileges) throws InvalidObjectException, MetaException, NoSuchObjectException {
    boolean committed = false;
    int now = (int) (System.currentTimeMillis() / 1000);
    try {
        openTransaction();
        List<Object> persistentObjs = new ArrayList<>();
        List<HiveObjectPrivilege> privilegeList = privileges.getPrivileges();
        if (CollectionUtils.isNotEmpty(privilegeList)) {
            Iterator<HiveObjectPrivilege> privIter = privilegeList.iterator();
            Set<String> privSet = new HashSet<>();
            while (privIter.hasNext()) {
                HiveObjectPrivilege privDef = privIter.next();
                HiveObjectRef hiveObject = privDef.getHiveObject();
                String privilegeStr = privDef.getGrantInfo().getPrivilege();
                String[] privs = privilegeStr.split(",");
                String userName = privDef.getPrincipalName();
                PrincipalType principalType = privDef.getPrincipalType();
                String grantor = privDef.getGrantInfo().getGrantor();
                String grantorType = privDef.getGrantInfo().getGrantorType().toString();
                boolean grantOption = privDef.getGrantInfo().isGrantOption();
                privSet.clear();
                if (principalType == PrincipalType.ROLE) {
                    validateRole(userName);
                }
                if (hiveObject.getObjectType() == HiveObjectType.GLOBAL) {
                    List<MGlobalPrivilege> globalPrivs = this.listPrincipalMGlobalGrants(userName, principalType);
                    if (globalPrivs != null) {
                        for (MGlobalPrivilege priv : globalPrivs) {
                            if (priv.getGrantor().equalsIgnoreCase(grantor)) {
                                privSet.add(priv.getPrivilege());
                            }
                        }
                    }
                    for (String privilege : privs) {
                        if (privSet.contains(privilege)) {
                            throw new InvalidObjectException(privilege + " is already granted by " + grantor);
                        }
                        MGlobalPrivilege mGlobalPrivs = new MGlobalPrivilege(userName, principalType.toString(), privilege, now, grantor, grantorType, grantOption);
                        persistentObjs.add(mGlobalPrivs);
                    }
                } else if (hiveObject.getObjectType() == HiveObjectType.DATABASE) {
                    MDatabase dbObj = getMDatabase(hiveObject.getDbName());
                    if (dbObj != null) {
                        List<MDBPrivilege> dbPrivs = this.listPrincipalMDBGrants(userName, principalType, hiveObject.getDbName());
                        if (dbPrivs != null) {
                            for (MDBPrivilege priv : dbPrivs) {
                                if (priv.getGrantor().equalsIgnoreCase(grantor)) {
                                    privSet.add(priv.getPrivilege());
                                }
                            }
                        }
                        for (String privilege : privs) {
                            if (privSet.contains(privilege)) {
                                throw new InvalidObjectException(privilege + " is already granted on database " + hiveObject.getDbName() + " by " + grantor);
                            }
                            MDBPrivilege mDb = new MDBPrivilege(userName, principalType.toString(), dbObj, privilege, now, grantor, grantorType, grantOption);
                            persistentObjs.add(mDb);
                        }
                    }
                } else if (hiveObject.getObjectType() == HiveObjectType.TABLE) {
                    MTable tblObj = getMTable(hiveObject.getDbName(), hiveObject.getObjectName());
                    if (tblObj != null) {
                        List<MTablePrivilege> tablePrivs = this.listAllMTableGrants(userName, principalType, hiveObject.getDbName(), hiveObject.getObjectName());
                        if (tablePrivs != null) {
                            for (MTablePrivilege priv : tablePrivs) {
                                if (priv.getGrantor() != null && priv.getGrantor().equalsIgnoreCase(grantor)) {
                                    privSet.add(priv.getPrivilege());
                                }
                            }
                        }
                        for (String privilege : privs) {
                            if (privSet.contains(privilege)) {
                                throw new InvalidObjectException(privilege + " is already granted on table [" + hiveObject.getDbName() + "," + hiveObject.getObjectName() + "] by " + grantor);
                            }
                            MTablePrivilege mTab = new MTablePrivilege(userName, principalType.toString(), tblObj, privilege, now, grantor, grantorType, grantOption);
                            persistentObjs.add(mTab);
                        }
                    }
                } else if (hiveObject.getObjectType() == HiveObjectType.PARTITION) {
                    MPartition partObj = this.getMPartition(hiveObject.getDbName(), hiveObject.getObjectName(), hiveObject.getPartValues());
                    String partName = null;
                    if (partObj != null) {
                        partName = partObj.getPartitionName();
                        List<MPartitionPrivilege> partPrivs = this.listPrincipalMPartitionGrants(userName, principalType, hiveObject.getDbName(), hiveObject.getObjectName(), partObj.getPartitionName());
                        if (partPrivs != null) {
                            for (MPartitionPrivilege priv : partPrivs) {
                                if (priv.getGrantor().equalsIgnoreCase(grantor)) {
                                    privSet.add(priv.getPrivilege());
                                }
                            }
                        }
                        for (String privilege : privs) {
                            if (privSet.contains(privilege)) {
                                throw new InvalidObjectException(privilege + " is already granted on partition [" + hiveObject.getDbName() + "," + hiveObject.getObjectName() + "," + partName + "] by " + grantor);
                            }
                            MPartitionPrivilege mTab = new MPartitionPrivilege(userName, principalType.toString(), partObj, privilege, now, grantor, grantorType, grantOption);
                            persistentObjs.add(mTab);
                        }
                    }
                } else if (hiveObject.getObjectType() == HiveObjectType.COLUMN) {
                    MTable tblObj = getMTable(hiveObject.getDbName(), hiveObject.getObjectName());
                    if (tblObj != null) {
                        if (hiveObject.getPartValues() != null) {
                            MPartition partObj = null;
                            List<MPartitionColumnPrivilege> colPrivs = null;
                            partObj = this.getMPartition(hiveObject.getDbName(), hiveObject.getObjectName(), hiveObject.getPartValues());
                            if (partObj == null) {
                                continue;
                            }
                            colPrivs = this.listPrincipalMPartitionColumnGrants(userName, principalType, hiveObject.getDbName(), hiveObject.getObjectName(), partObj.getPartitionName(), hiveObject.getColumnName());
                            if (colPrivs != null) {
                                for (MPartitionColumnPrivilege priv : colPrivs) {
                                    if (priv.getGrantor().equalsIgnoreCase(grantor)) {
                                        privSet.add(priv.getPrivilege());
                                    }
                                }
                            }
                            for (String privilege : privs) {
                                if (privSet.contains(privilege)) {
                                    throw new InvalidObjectException(privilege + " is already granted on column " + hiveObject.getColumnName() + " [" + hiveObject.getDbName() + "," + hiveObject.getObjectName() + "," + partObj.getPartitionName() + "] by " + grantor);
                                }
                                MPartitionColumnPrivilege mCol = new MPartitionColumnPrivilege(userName, principalType.toString(), partObj, hiveObject.getColumnName(), privilege, now, grantor, grantorType, grantOption);
                                persistentObjs.add(mCol);
                            }
                        } else {
                            List<MTableColumnPrivilege> colPrivs = null;
                            colPrivs = this.listPrincipalMTableColumnGrants(userName, principalType, hiveObject.getDbName(), hiveObject.getObjectName(), hiveObject.getColumnName());
                            if (colPrivs != null) {
                                for (MTableColumnPrivilege priv : colPrivs) {
                                    if (priv.getGrantor().equalsIgnoreCase(grantor)) {
                                        privSet.add(priv.getPrivilege());
                                    }
                                }
                            }
                            for (String privilege : privs) {
                                if (privSet.contains(privilege)) {
                                    throw new InvalidObjectException(privilege + " is already granted on column " + hiveObject.getColumnName() + " [" + hiveObject.getDbName() + "," + hiveObject.getObjectName() + "] by " + grantor);
                                }
                                MTableColumnPrivilege mCol = new MTableColumnPrivilege(userName, principalType.toString(), tblObj, hiveObject.getColumnName(), privilege, now, grantor, grantorType, grantOption);
                                persistentObjs.add(mCol);
                            }
                        }
                    }
                }
            }
        }
        if (CollectionUtils.isNotEmpty(persistentObjs)) {
            pm.makePersistentAll(persistentObjs);
        }
        committed = commitTransaction();
    } finally {
        if (!committed) {
            rollbackTransaction();
        }
    }
    return committed;
}
Also used : ArrayList(java.util.ArrayList) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) List(java.util.List) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege) HashSet(java.util.HashSet) MPartition(org.apache.hadoop.hive.metastore.model.MPartition) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) MDBPrivilege(org.apache.hadoop.hive.metastore.model.MDBPrivilege) MGlobalPrivilege(org.apache.hadoop.hive.metastore.model.MGlobalPrivilege) 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) MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) MTable(org.apache.hadoop.hive.metastore.model.MTable) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege)

Example 14 with MPartitionPrivilege

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

the class ObjectStore method dropTable.

@Override
public boolean dropTable(String dbName, String tableName) throws MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException {
    boolean materializedView = false;
    boolean success = false;
    try {
        openTransaction();
        MTable tbl = getMTable(dbName, tableName);
        pm.retrieve(tbl);
        if (tbl != null) {
            materializedView = TableType.MATERIALIZED_VIEW.toString().equals(tbl.getTableType());
            // first remove all the grants
            List<MTablePrivilege> tabGrants = listAllTableGrants(dbName, tableName);
            if (CollectionUtils.isNotEmpty(tabGrants)) {
                pm.deletePersistentAll(tabGrants);
            }
            List<MTableColumnPrivilege> tblColGrants = listTableAllColumnGrants(dbName, tableName);
            if (CollectionUtils.isNotEmpty(tblColGrants)) {
                pm.deletePersistentAll(tblColGrants);
            }
            List<MPartitionPrivilege> partGrants = this.listTableAllPartitionGrants(dbName, tableName);
            if (CollectionUtils.isNotEmpty(partGrants)) {
                pm.deletePersistentAll(partGrants);
            }
            List<MPartitionColumnPrivilege> partColGrants = listTableAllPartitionColumnGrants(dbName, tableName);
            if (CollectionUtils.isNotEmpty(partColGrants)) {
                pm.deletePersistentAll(partColGrants);
            }
            // delete column statistics if present
            try {
                deleteTableColumnStatistics(dbName, tableName, null);
            } catch (NoSuchObjectException e) {
                LOG.info("Found no table level column statistics associated with db {}" + " table {} record to delete", dbName, tableName);
            }
            List<MConstraint> tabConstraints = listAllTableConstraintsWithOptionalConstraintName(dbName, tableName, null);
            if (CollectionUtils.isNotEmpty(tabConstraints)) {
                pm.deletePersistentAll(tabConstraints);
            }
            preDropStorageDescriptor(tbl.getSd());
            if (materializedView) {
                dropCreationMetadata(tbl.getDatabase().getName(), tbl.getTableName());
            }
            // then remove the table
            pm.deletePersistentAll(tbl);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        } else {
            if (materializedView) {
                MaterializationsInvalidationCache.get().dropMaterializedView(dbName, tableName);
            }
        }
    }
    return success;
}
Also used : MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MTable(org.apache.hadoop.hive.metastore.model.MTable) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)

Example 15 with MPartitionPrivilege

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

the class ObjectStore method listPrincipalPartitionGrants.

@Override
public List<HiveObjectPrivilege> listPrincipalPartitionGrants(String principalName, PrincipalType principalType, String dbName, String tableName, List<String> partValues, String partName) {
    List<MPartitionPrivilege> mParts = listPrincipalMPartitionGrants(principalName, principalType, dbName, tableName, partName);
    if (mParts.isEmpty()) {
        return Collections.emptyList();
    }
    List<HiveObjectPrivilege> result = new ArrayList<>();
    for (int i = 0; i < mParts.size(); i++) {
        MPartitionPrivilege sPart = mParts.get(i);
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.PARTITION, dbName, tableName, partValues, null);
        HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef, sPart.getPrincipalName(), principalType, new PrivilegeGrantInfo(sPart.getPrivilege(), sPart.getCreateTime(), sPart.getGrantor(), PrincipalType.valueOf(sPart.getGrantorType()), sPart.getGrantOption()));
        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) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) ArrayList(java.util.ArrayList) 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)

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 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 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