Search in sources :

Example 1 with GetPartitionsPsWithAuthRequest

use of org.apache.hadoop.hive.metastore.api.GetPartitionsPsWithAuthRequest in project hive by apache.

the class Hive method getPartitions.

/**
 * get all the partitions that the table has
 *
 * @param tbl
 *          object for which partition is needed
 * @return list of partition objects
 */
public List<Partition> getPartitions(Table tbl) throws HiveException {
    PerfLogger perfLogger = SessionState.getPerfLogger();
    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_PARTITIONS);
    try {
        if (tbl.isPartitioned()) {
            List<org.apache.hadoop.hive.metastore.api.Partition> tParts;
            try {
                GetPartitionsPsWithAuthRequest req = new GetPartitionsPsWithAuthRequest();
                req.setTblName(tbl.getTableName());
                req.setDbName(tbl.getDbName());
                req.setUserName(getUserName());
                req.setMaxParts((short) -1);
                req.setGroupNames(getGroupNames());
                if (AcidUtils.isTransactionalTable(tbl)) {
                    ValidWriteIdList validWriteIdList = getValidWriteIdList(tbl.getDbName(), tbl.getTableName());
                    req.setValidWriteIdList(validWriteIdList != null ? validWriteIdList.toString() : null);
                    req.setId(tbl.getTTable().getId());
                }
                GetPartitionsPsWithAuthResponse res = getMSC().listPartitionsWithAuthInfoRequest(req);
                tParts = res.getPartitions();
            } catch (Exception e) {
                LOG.error("Failed getPartitions", e);
                throw new HiveException(e);
            }
            List<Partition> parts = new ArrayList<>(tParts.size());
            for (org.apache.hadoop.hive.metastore.api.Partition tpart : tParts) {
                parts.add(new Partition(tbl, tpart));
            }
            return parts;
        } else {
            return Collections.singletonList(new Partition(tbl));
        }
    } finally {
        perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.HIVE_GET_PARTITIONS, "HS2-cache");
    }
}
Also used : PerfLogger(org.apache.hadoop.hive.ql.log.PerfLogger) ArrayList(java.util.ArrayList) GetPartitionsPsWithAuthRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsPsWithAuthRequest) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) LockException(org.apache.hadoop.hive.ql.lockmgr.LockException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) TApplicationException(org.apache.thrift.TApplicationException) TException(org.apache.thrift.TException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) FileNotFoundException(java.io.FileNotFoundException) JDODataStoreException(javax.jdo.JDODataStoreException) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) GetPartitionsPsWithAuthResponse(org.apache.hadoop.hive.metastore.api.GetPartitionsPsWithAuthResponse)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 JDODataStoreException (javax.jdo.JDODataStoreException)1 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)1 HiveMetaException (org.apache.hadoop.hive.metastore.HiveMetaException)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 GetPartitionsPsWithAuthRequest (org.apache.hadoop.hive.metastore.api.GetPartitionsPsWithAuthRequest)1 GetPartitionsPsWithAuthResponse (org.apache.hadoop.hive.metastore.api.GetPartitionsPsWithAuthResponse)1 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)1 PerfLogger (org.apache.hadoop.hive.ql.log.PerfLogger)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 TApplicationException (org.apache.thrift.TApplicationException)1 TException (org.apache.thrift.TException)1