Search in sources :

Example 1 with MPartition

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

the class ObjectStore method deletePartitionColumnStatistics.

@Override
public boolean deletePartitionColumnStatistics(String dbName, String tableName, String partName, List<String> partVals, String colName) throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException {
    boolean ret = false;
    Query query = null;
    if (dbName == null) {
        dbName = MetaStoreUtils.DEFAULT_DATABASE_NAME;
    }
    if (tableName == null) {
        throw new InvalidInputException("Table name is null.");
    }
    try {
        openTransaction();
        MTable mTable = getMTable(dbName, tableName);
        MPartitionColumnStatistics mStatsObj;
        List<MPartitionColumnStatistics> mStatsObjColl;
        if (mTable == null) {
            throw new NoSuchObjectException("Table " + tableName + "  for which stats deletion is requested doesn't exist");
        }
        MPartition mPartition = getMPartition(dbName, tableName, partVals);
        if (mPartition == null) {
            throw new NoSuchObjectException("Partition " + partName + " for which stats deletion is requested doesn't exist");
        }
        query = pm.newQuery(MPartitionColumnStatistics.class);
        String filter;
        String parameters;
        if (colName != null) {
            filter = "partition.partitionName == t1 && dbName == t2 && tableName == t3 && " + "colName == t4";
            parameters = "java.lang.String t1, java.lang.String t2, " + "java.lang.String t3, java.lang.String t4";
        } else {
            filter = "partition.partitionName == t1 && dbName == t2 && tableName == t3";
            parameters = "java.lang.String t1, java.lang.String t2, java.lang.String t3";
        }
        query.setFilter(filter);
        query.declareParameters(parameters);
        if (colName != null) {
            query.setUnique(true);
            mStatsObj = (MPartitionColumnStatistics) query.executeWithArray(partName.trim(), HiveStringUtils.normalizeIdentifier(dbName), HiveStringUtils.normalizeIdentifier(tableName), HiveStringUtils.normalizeIdentifier(colName));
            pm.retrieve(mStatsObj);
            if (mStatsObj != null) {
                pm.deletePersistent(mStatsObj);
            } else {
                throw new NoSuchObjectException("Column stats doesn't exist for db=" + dbName + " table=" + tableName + " partition=" + partName + " col=" + colName);
            }
        } else {
            mStatsObjColl = (List<MPartitionColumnStatistics>) query.execute(partName.trim(), HiveStringUtils.normalizeIdentifier(dbName), HiveStringUtils.normalizeIdentifier(tableName));
            pm.retrieveAll(mStatsObjColl);
            if (mStatsObjColl != null) {
                pm.deletePersistentAll(mStatsObjColl);
            } else {
                throw new NoSuchObjectException("Column stats doesn't exist for db=" + dbName + " table=" + tableName + " partition" + partName);
            }
        }
        ret = commitTransaction();
    } catch (NoSuchObjectException e) {
        rollbackTransaction();
        throw e;
    } finally {
        if (!ret) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
    return ret;
}
Also used : InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) MTable(org.apache.hadoop.hive.metastore.model.MTable) Query(javax.jdo.Query) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MPartitionColumnStatistics(org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 2 with MPartition

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

the class ObjectStore method convertPartCols.

private List<HiveObjectPrivilege> convertPartCols(List<MPartitionColumnPrivilege> privs) {
    List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
    for (MPartitionColumnPrivilege priv : privs) {
        String pname = priv.getPrincipalName();
        PrincipalType ptype = PrincipalType.valueOf(priv.getPrincipalType());
        MPartition mpartition = priv.getPartition();
        MTable mtable = mpartition.getTable();
        MDatabase mdatabase = mtable.getDatabase();
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.COLUMN, mdatabase.getName(), mtable.getTableName(), mpartition.getValues(), priv.getColumnName());
        PrivilegeGrantInfo grantor = new PrivilegeGrantInfo(priv.getPrivilege(), priv.getCreateTime(), priv.getGrantor(), PrincipalType.valueOf(priv.getGrantorType()), priv.getGrantOption());
        result.add(new HiveObjectPrivilege(objectRef, pname, ptype, grantor));
    }
    return result;
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) MTable(org.apache.hadoop.hive.metastore.model.MTable) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 3 with MPartition

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

the class ObjectStore method convertToMPart.

/**
   * Convert a Partition object into an MPartition, which is an object backed by the db
   * If the Partition's set of columns is the same as the parent table's AND useTableCD
   * is true, then this partition's storage descriptor's column descriptor will point
   * to the same one as the table's storage descriptor.
   * @param part the partition to convert
   * @param useTableCD whether to try to use the parent table's column descriptor.
   * @return the model partition object
   * @throws InvalidObjectException
   * @throws MetaException
   */
private MPartition convertToMPart(Partition part, boolean useTableCD) throws InvalidObjectException, MetaException {
    if (part == null) {
        return null;
    }
    MTable mt = getMTable(part.getDbName(), part.getTableName());
    if (mt == null) {
        throw new InvalidObjectException("Partition doesn't have a valid table or database name");
    }
    // If this partition's set of columns is the same as the parent table's,
    // use the parent table's, so we do not create a duplicate column descriptor,
    // thereby saving space
    MStorageDescriptor msd;
    if (useTableCD && mt.getSd() != null && mt.getSd().getCD() != null && mt.getSd().getCD().getCols() != null && part.getSd() != null && convertToFieldSchemas(mt.getSd().getCD().getCols()).equals(part.getSd().getCols())) {
        msd = convertToMStorageDescriptor(part.getSd(), mt.getSd().getCD());
    } else {
        msd = convertToMStorageDescriptor(part.getSd());
    }
    return new MPartition(Warehouse.makePartName(convertToFieldSchemas(mt.getPartitionKeys()), part.getValues()), mt, part.getValues(), part.getCreateTime(), part.getLastAccessTime(), msd, part.getParameters());
}
Also used : MTable(org.apache.hadoop.hive.metastore.model.MTable) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MStorageDescriptor(org.apache.hadoop.hive.metastore.model.MStorageDescriptor) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 4 with MPartition

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

the class ObjectStore method getPartitionWithAuth.

@Override
public Partition getPartitionWithAuth(String dbName, String tblName, List<String> partVals, String user_name, List<String> group_names) throws NoSuchObjectException, MetaException, InvalidObjectException {
    boolean success = false;
    try {
        openTransaction();
        MPartition mpart = getMPartition(dbName, tblName, partVals);
        if (mpart == null) {
            commitTransaction();
            throw new NoSuchObjectException("partition values=" + partVals.toString());
        }
        Partition part = null;
        MTable mtbl = mpart.getTable();
        part = convertToPart(mpart);
        if ("TRUE".equalsIgnoreCase(mtbl.getParameters().get("PARTITION_LEVEL_PRIVILEGE"))) {
            String partName = Warehouse.makePartName(this.convertToFieldSchemas(mtbl.getPartitionKeys()), partVals);
            PrincipalPrivilegeSet partAuth = this.getPartitionPrivilegeSet(dbName, tblName, partName, user_name, group_names);
            part.setPrivileges(partAuth);
        }
        success = commitTransaction();
        return part;
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
}
Also used : MPartition(org.apache.hadoop.hive.metastore.model.MPartition) Partition(org.apache.hadoop.hive.metastore.api.Partition) MTable(org.apache.hadoop.hive.metastore.model.MTable) PrincipalPrivilegeSet(org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Example 5 with MPartition

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

the class ObjectStore method convertPartition.

private List<HiveObjectPrivilege> convertPartition(List<MPartitionPrivilege> privs) {
    List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
    for (MPartitionPrivilege priv : privs) {
        String pname = priv.getPrincipalName();
        PrincipalType ptype = PrincipalType.valueOf(priv.getPrincipalType());
        MPartition mpartition = priv.getPartition();
        MTable mtable = mpartition.getTable();
        MDatabase mdatabase = mtable.getDatabase();
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.PARTITION, mdatabase.getName(), mtable.getTableName(), mpartition.getValues(), null);
        PrivilegeGrantInfo grantor = new PrivilegeGrantInfo(priv.getPrivilege(), priv.getCreateTime(), priv.getGrantor(), PrincipalType.valueOf(priv.getGrantorType()), priv.getGrantOption());
        result.add(new HiveObjectPrivilege(objectRef, pname, ptype, grantor));
    }
    return result;
}
Also used : MDatabase(org.apache.hadoop.hive.metastore.model.MDatabase) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) MTable(org.apache.hadoop.hive.metastore.model.MTable) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) MPartition(org.apache.hadoop.hive.metastore.model.MPartition)

Aggregations

MPartition (org.apache.hadoop.hive.metastore.model.MPartition)21 MTable (org.apache.hadoop.hive.metastore.model.MTable)14 ArrayList (java.util.ArrayList)11 Partition (org.apache.hadoop.hive.metastore.api.Partition)10 Query (javax.jdo.Query)6 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)5 MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)5 MPartitionPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)5 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)4 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)4 MTableColumnPrivilege (org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)4 MTablePrivilege (org.apache.hadoop.hive.metastore.model.MTablePrivilege)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)3 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)3 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)3 PrincipalPrivilegeSet (org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet)3 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)3 MDatabase (org.apache.hadoop.hive.metastore.model.MDatabase)3