Search in sources :

Example 6 with GetPartitionsByNamesRequest

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

the class Hive method getPartitionsByNames.

public List<org.apache.hadoop.hive.metastore.api.Partition> getPartitionsByNames(String dbName, String tableName, List<String> partitionNames, Table t) throws HiveException {
    try {
        GetPartitionsByNamesRequest req = new GetPartitionsByNamesRequest();
        req.setDb_name(dbName);
        req.setTbl_name(tableName);
        req.setNames(partitionNames);
        return getPartitionsByNames(req, t);
    } catch (Exception e) {
        LOG.error("Failed getPartitionsByNames", e);
        throw new HiveException(e);
    }
}
Also used : GetPartitionsByNamesRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesRequest) 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)

Example 7 with GetPartitionsByNamesRequest

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

the class Hive method getPartitionsByNames.

/**
 * Get all partitions of the table that matches the list of given partition names.
 *
 * @param tbl
 *          object for which partition is needed. Must be partitioned.
 * @param partNames
 *          list of partition names
 * @param getColStats
 *          if true, Partition object includes column statistics for that partition.
 * @return list of partition objects
 * @throws HiveException
 */
public List<Partition> getPartitionsByNames(Table tbl, List<String> partNames, boolean getColStats) throws HiveException {
    if (!tbl.isPartitioned()) {
        throw new HiveException(ErrorMsg.TABLE_NOT_PARTITIONED, tbl.getTableName());
    }
    List<Partition> partitions = new ArrayList<Partition>(partNames.size());
    int batchSize = HiveConf.getIntVar(conf, HiveConf.ConfVars.METASTORE_BATCH_RETRIEVE_MAX);
    // TODO: might want to increase the default batch size. 1024 is viable; MS gets OOM if too high.
    int nParts = partNames.size();
    int nBatches = nParts / batchSize;
    try {
        for (int i = 0; i < nBatches; ++i) {
            GetPartitionsByNamesRequest req = new GetPartitionsByNamesRequest();
            req.setDb_name(tbl.getDbName());
            req.setTbl_name(tbl.getTableName());
            req.setNames(partNames.subList(i * batchSize, (i + 1) * batchSize));
            req.setGet_col_stats(false);
            List<org.apache.hadoop.hive.metastore.api.Partition> tParts = getPartitionsByNames(req, tbl);
            if (tParts != null) {
                for (org.apache.hadoop.hive.metastore.api.Partition tpart : tParts) {
                    partitions.add(new Partition(tbl, tpart));
                }
            }
        }
        if (nParts > nBatches * batchSize) {
            String validWriteIdList = null;
            Long tableId = null;
            if (AcidUtils.isTransactionalTable(tbl)) {
                ValidWriteIdList vWriteIdList = getValidWriteIdList(tbl.getDbName(), tbl.getTableName());
                validWriteIdList = vWriteIdList != null ? vWriteIdList.toString() : null;
                tableId = tbl.getTTable().getId();
            }
            List<org.apache.hadoop.hive.metastore.api.Partition> tParts = getMSC().getPartitionsByNames(tbl.getDbName(), tbl.getTableName(), partNames.subList(nBatches * batchSize, nParts), getColStats, Constants.HIVE_ENGINE);
            if (tParts != null) {
                for (org.apache.hadoop.hive.metastore.api.Partition tpart : tParts) {
                    partitions.add(new Partition(tbl, tpart));
                }
            }
        }
    } catch (Exception e) {
        throw new HiveException(e);
    }
    return partitions;
}
Also used : ArrayList(java.util.ArrayList) 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) 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) GetPartitionsByNamesRequest(org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesRequest) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList)

Aggregations

GetPartitionsByNamesRequest (org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesRequest)7 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 JDODataStoreException (javax.jdo.JDODataStoreException)2 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)2 HiveMetaException (org.apache.hadoop.hive.metastore.HiveMetaException)2 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)2 GetPartitionsByNamesResult (org.apache.hadoop.hive.metastore.api.GetPartitionsByNamesResult)2 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)2 Partition (org.apache.hadoop.hive.metastore.api.Partition)2 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)2 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)2 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)2