Search in sources :

Example 6 with PartitionsByExprRequest

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

the class Hive method buildPartitionByExprRequest.

private PartitionsByExprRequest buildPartitionByExprRequest(Table tbl, byte[] exprBytes, String defaultPartitionName, HiveConf conf, String validWriteIdList) {
    PartitionsByExprRequest req = new PartitionsByExprRequest(tbl.getDbName(), tbl.getTableName(), ByteBuffer.wrap(exprBytes));
    if (defaultPartitionName != null) {
        req.setDefaultPartitionName(defaultPartitionName);
    }
    req.setCatName(getDefaultCatalog(conf));
    req.setValidWriteIdList(validWriteIdList);
    req.setId(tbl.getTTable().getId());
    return req;
}
Also used : PartitionsByExprRequest(org.apache.hadoop.hive.metastore.api.PartitionsByExprRequest)

Example 7 with PartitionsByExprRequest

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

the class Hive method getPartitionsByExpr.

/**
 * Get a list of Partitions by expr.
 * @param tbl The table containing the partitions.
 * @param expr A serialized expression for partition predicates.
 * @param conf Hive config.
 * @param partitions the resulting list of partitions
 * @return whether the resulting list contains partitions which may or may not match the expr
 */
public boolean getPartitionsByExpr(Table tbl, ExprNodeGenericFuncDesc expr, HiveConf conf, List<Partition> partitions) throws HiveException, TException {
    PerfLogger perfLogger = SessionState.getPerfLogger();
    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_PARTITIONS_BY_EXPR);
    try {
        Preconditions.checkNotNull(partitions);
        byte[] exprBytes = SerializationUtilities.serializeExpressionToKryo(expr);
        String defaultPartitionName = HiveConf.getVar(conf, ConfVars.DEFAULTPARTITIONNAME);
        List<org.apache.hadoop.hive.metastore.api.PartitionSpec> msParts = new ArrayList<>();
        ValidWriteIdList validWriteIdList = null;
        PartitionsByExprRequest req = buildPartitionByExprRequest(tbl, exprBytes, defaultPartitionName, conf, null);
        if (AcidUtils.isTransactionalTable(tbl)) {
            validWriteIdList = getValidWriteIdList(tbl.getDbName(), tbl.getTableName());
            req.setValidWriteIdList(validWriteIdList != null ? validWriteIdList.toString() : null);
            req.setId(tbl.getTTable().getId());
        }
        boolean hasUnknownParts = getMSC().listPartitionsSpecByExpr(req, msParts);
        partitions.addAll(convertFromPartSpec(msParts.iterator(), tbl));
        return hasUnknownParts;
    } finally {
        perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.HIVE_GET_PARTITIONS_BY_EXPR, "HS2-cache");
    }
}
Also used : ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) PartitionsByExprRequest(org.apache.hadoop.hive.metastore.api.PartitionsByExprRequest) PerfLogger(org.apache.hadoop.hive.ql.log.PerfLogger) ArrayList(java.util.ArrayList) PartitionSpec(org.apache.hadoop.hive.metastore.api.PartitionSpec)

Example 8 with PartitionsByExprRequest

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

the class Hive method getPartitionNames.

public List<String> getPartitionNames(Table tbl, ExprNodeGenericFuncDesc expr, String order, short maxParts) throws HiveException {
    List<String> names = null;
    // the exprBytes should not be null by thrift definition
    byte[] exprBytes = { (byte) -1 };
    if (expr != null) {
        exprBytes = SerializationUtilities.serializeExpressionToKryo(expr);
    }
    try {
        String defaultPartitionName = HiveConf.getVar(conf, ConfVars.DEFAULTPARTITIONNAME);
        PartitionsByExprRequest req = new PartitionsByExprRequest(tbl.getDbName(), tbl.getTableName(), ByteBuffer.wrap(exprBytes));
        if (defaultPartitionName != null) {
            req.setDefaultPartitionName(defaultPartitionName);
        }
        if (maxParts >= 0) {
            req.setMaxParts(maxParts);
        }
        req.setOrder(order);
        req.setCatName(tbl.getCatalogName());
        if (AcidUtils.isTransactionalTable(tbl)) {
            ValidWriteIdList validWriteIdList = getValidWriteIdList(tbl.getDbName(), tbl.getTableName());
            req.setValidWriteIdList(validWriteIdList != null ? validWriteIdList.toString() : null);
            req.setId(tbl.getTTable().getId());
        }
        names = getMSC().listPartitionNames(req);
    } catch (NoSuchObjectException nsoe) {
        return Lists.newArrayList();
    } catch (Exception e) {
        LOG.error("Failed getPartitionNames", e);
        throw new HiveException(e);
    }
    return names;
}
Also used : ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) PartitionsByExprRequest(org.apache.hadoop.hive.metastore.api.PartitionsByExprRequest) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) 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 9 with PartitionsByExprRequest

use of org.apache.hadoop.hive.metastore.api.PartitionsByExprRequest in project metacat by Netflix.

the class CatalogThriftHiveMetastore method drop_partitions_req.

/**
 * {@inheritDoc}
 */
@Override
public DropPartitionsResult drop_partitions_req(final DropPartitionsRequest request) throws TException {
    return requestWrapper("drop_partitions_req", new Object[] { request }, () -> {
        final String databaseName = request.getDbName();
        final String tableName = request.getTblName();
        final boolean ifExists = request.isSetIfExists() && request.isIfExists();
        final boolean needResult = !request.isSetNeedResult() || request.isNeedResult();
        final List<Partition> parts = Lists.newArrayList();
        final List<String> partNames = Lists.newArrayList();
        int minCount = 0;
        final RequestPartsSpec spec = request.getParts();
        if (spec.isSetExprs()) {
            final Table table = get_table(databaseName, tableName);
            // Dropping by expressions.
            for (DropPartitionsExpr expr : spec.getExprs()) {
                // At least one partition per expression, if not ifExists
                ++minCount;
                final PartitionsByExprResult partitionsByExprResult = get_partitions_by_expr(new PartitionsByExprRequest(databaseName, tableName, expr.bufferForExpr()));
                if (partitionsByExprResult.isHasUnknownPartitions()) {
                    // Expr is built by DDLSA, it should only contain part cols and simple ops
                    throw new MetaException("Unexpected unknown partitions to drop");
                }
                parts.addAll(partitionsByExprResult.getPartitions());
            }
            final List<String> colNames = new ArrayList<>(table.getPartitionKeys().size());
            for (FieldSchema col : table.getPartitionKeys()) {
                colNames.add(col.getName());
            }
            if (!colNames.isEmpty()) {
                parts.forEach(partition -> partNames.add(FileUtils.makePartName(colNames, partition.getValues())));
            }
        } else if (spec.isSetNames()) {
            partNames.addAll(spec.getNames());
            minCount = partNames.size();
            parts.addAll(get_partitions_by_names(databaseName, tableName, partNames));
        } else {
            throw new MetaException("Partition spec is not set");
        }
        if ((parts.size() < minCount) && !ifExists) {
            throw new NoSuchObjectException("Some partitions to drop are missing");
        }
        partV1.deletePartitions(catalogName, databaseName, tableName, partNames);
        final DropPartitionsResult result = new DropPartitionsResult();
        if (needResult) {
            result.setPartitions(parts);
        }
        return result;
    });
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) DropPartitionsExpr(org.apache.hadoop.hive.metastore.api.DropPartitionsExpr) Table(org.apache.hadoop.hive.metastore.api.Table) PartitionsByExprResult(org.apache.hadoop.hive.metastore.api.PartitionsByExprResult) DropPartitionsResult(org.apache.hadoop.hive.metastore.api.DropPartitionsResult) PartitionsByExprRequest(org.apache.hadoop.hive.metastore.api.PartitionsByExprRequest) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ArrayList(java.util.ArrayList) RequestPartsSpec(org.apache.hadoop.hive.metastore.api.RequestPartsSpec) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 10 with PartitionsByExprRequest

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

the class TestSessionHiveMetastoreClientListPartitionsTempTable method checkPartitionNames.

private void checkPartitionNames(List<String> expected, short numParts, String order, String defaultPartName, ExprNodeGenericFuncDesc expr, Table t) throws Exception {
    PartitionsByExprRequest request = new PartitionsByExprRequest();
    request.setDbName(DB_NAME);
    request.setTblName(TABLE_NAME);
    byte[] exprs = { (byte) -1 };
    if (expr != null) {
        exprs = SerializationUtilities.serializeExpressionToKryo(expr);
    }
    request.setExpr(exprs);
    request.setMaxParts(numParts);
    request.setOrder(order);
    request.setDefaultPartitionName(defaultPartName);
    request.setId(t.getId());
    List<String> partitionNames = getClient().listPartitionNames(request);
    assertArrayEquals(expected.toArray(), partitionNames.toArray());
}
Also used : PartitionsByExprRequest(org.apache.hadoop.hive.metastore.api.PartitionsByExprRequest)

Aggregations

PartitionsByExprRequest (org.apache.hadoop.hive.metastore.api.PartitionsByExprRequest)16 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)6 PartitionSpec (org.apache.hadoop.hive.metastore.api.PartitionSpec)5 Table (org.apache.hadoop.hive.metastore.api.Table)5 TestMetastoreExpr (org.apache.hadoop.hive.metastore.TestMetastoreExpr)3 Partition (org.apache.hadoop.hive.metastore.api.Partition)3 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 ExecutionException (java.util.concurrent.ExecutionException)1 JDODataStoreException (javax.jdo.JDODataStoreException)1 HiveMetaException (org.apache.hadoop.hive.metastore.HiveMetaException)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 DropPartitionsExpr (org.apache.hadoop.hive.metastore.api.DropPartitionsExpr)1 DropPartitionsResult (org.apache.hadoop.hive.metastore.api.DropPartitionsResult)1