Search in sources :

Example 1 with PartitionExpression

use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.

the class PTFTranslator method translate.

private PartitionDef translate(ShapeDetails inpShape, PartitionSpec spec) throws SemanticException {
    if (spec == null || spec.getExpressions() == null || spec.getExpressions().size() == 0) {
        return null;
    }
    PartitionDef pDef = new PartitionDef();
    for (PartitionExpression pExpr : spec.getExpressions()) {
        PTFExpressionDef expDef = translate(inpShape, pExpr);
        pDef.addExpression(expDef);
    }
    return pDef;
}
Also used : PartitionExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression) PartitionDef(org.apache.hadoop.hive.ql.plan.ptf.PartitionDef) PTFExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.PTFExpressionDef)

Example 2 with PartitionExpression

use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.

the class WindowingSpec method applyConstantPartition.

private void applyConstantPartition(WindowSpec wdwSpec) {
    PartitionSpec partSpec = wdwSpec.getPartition();
    if (partSpec == null) {
        partSpec = new PartitionSpec();
        PartitionExpression partExpr = new PartitionExpression();
        partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0")));
        partSpec.addExpression(partExpr);
        wdwSpec.setPartition(partSpec);
    }
}
Also used : PartitionExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression) CommonToken(org.antlr.runtime.CommonToken) PartitionSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionSpec)

Example 3 with PartitionExpression

use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.

the class SemanticAnalyzer method genReduceSinkPlanForWindowing.

private Operator genReduceSinkPlanForWindowing(WindowingSpec spec, RowResolver inputRR, Operator input) throws SemanticException {
    ArrayList<ExprNodeDesc> partCols = new ArrayList<ExprNodeDesc>();
    ArrayList<ExprNodeDesc> orderCols = new ArrayList<ExprNodeDesc>();
    StringBuilder order = new StringBuilder();
    StringBuilder nullOrder = new StringBuilder();
    for (PartitionExpression partCol : spec.getQueryPartitionSpec().getExpressions()) {
        ExprNodeDesc partExpr = genExprNodeDesc(partCol.getExpression(), inputRR);
        if (ExprNodeDescUtils.indexOf(partExpr, partCols) < 0) {
            partCols.add(partExpr);
            orderCols.add(partExpr);
            order.append('+');
            nullOrder.append('a');
        }
    }
    if (spec.getQueryOrderSpec() != null) {
        for (OrderExpression orderCol : spec.getQueryOrderSpec().getExpressions()) {
            ExprNodeDesc orderExpr = genExprNodeDesc(orderCol.getExpression(), inputRR);
            char orderChar = orderCol.getOrder() == PTFInvocationSpec.Order.ASC ? '+' : '-';
            char nullOrderChar = orderCol.getNullOrder() == PTFInvocationSpec.NullOrder.NULLS_FIRST ? 'a' : 'z';
            int index = ExprNodeDescUtils.indexOf(orderExpr, orderCols);
            if (index >= 0) {
                order.setCharAt(index, orderChar);
                nullOrder.setCharAt(index, nullOrderChar);
                continue;
            }
            orderCols.add(genExprNodeDesc(orderCol.getExpression(), inputRR));
            order.append(orderChar);
            nullOrder.append(nullOrderChar);
        }
    }
    return genReduceSinkPlan(input, partCols, orderCols, order.toString(), nullOrder.toString(), -1, Operation.NOT_ACID);
}
Also used : PartitionExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression) OrderExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderExpression) ArrayList(java.util.ArrayList) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc)

Example 4 with PartitionExpression

use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.

the class PTFTranslator method addPartitionExpressionsToOrderList.

protected static ArrayList<OrderExpression> addPartitionExpressionsToOrderList(ArrayList<PartitionExpression> partCols, ArrayList<OrderExpression> orderCols) throws SemanticException {
    int numOfPartColumns = 0;
    int chkSize = partCols.size();
    chkSize = chkSize > orderCols.size() ? orderCols.size() : chkSize;
    for (int i = 0; i < chkSize; i++) {
        if (orderCols.get(i).getExpression().toStringTree().equals(partCols.get(i).getExpression().toStringTree())) {
            numOfPartColumns++;
        } else {
            break;
        }
    }
    if (numOfPartColumns != 0 && numOfPartColumns != partCols.size()) {
        List<String> partitionColumnNames = new ArrayList<String>();
        for (PartitionExpression partitionExpression : partCols) {
            ASTNode column = partitionExpression.getExpression();
            if (column != null && column.getChildCount() > 0) {
                partitionColumnNames.add(column.getChild(0).getText());
            }
        }
        throw new SemanticException(String.format("all partition columns %s must be in order clause or none should be specified", partitionColumnNames.toString()));
    }
    ArrayList<OrderExpression> combinedOrdExprs = new ArrayList<OrderExpression>();
    if (numOfPartColumns == 0) {
        for (PartitionExpression partCol : partCols) {
            OrderExpression orderCol = new OrderExpression(partCol);
            combinedOrdExprs.add(orderCol);
        }
    }
    combinedOrdExprs.addAll(orderCols);
    return combinedOrdExprs;
}
Also used : PartitionExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression) OrderExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderExpression) ArrayList(java.util.ArrayList)

Example 5 with PartitionExpression

use of org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression in project hive by apache.

the class PTFTranslator method applyConstantPartition.

/*
   * If this the first PPTF in the chain and there is no partition specified
   * then assume the user wants to include the entire input in 1 partition.
   */
private static void applyConstantPartition(PartitionedTableFunctionSpec spec) {
    if (spec.getPartition() != null) {
        return;
    }
    PTFInputSpec iSpec = spec.getInput();
    if (iSpec instanceof PTFInputSpec) {
        PartitionSpec partSpec = new PartitionSpec();
        PartitionExpression partExpr = new PartitionExpression();
        partExpr.setExpression(new ASTNode(new CommonToken(HiveParser.Number, "0")));
        partSpec.addExpression(partExpr);
        spec.setPartition(partSpec);
    }
}
Also used : PTFInputSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFInputSpec) PartitionExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression) CommonToken(org.antlr.runtime.CommonToken) PartitionSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionSpec)

Aggregations

PartitionExpression (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression)8 OrderExpression (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderExpression)4 PartitionSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionSpec)4 ArrayList (java.util.ArrayList)3 CommonToken (org.antlr.runtime.CommonToken)2 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)2 RexFieldCollation (org.apache.calcite.rex.RexFieldCollation)1 RexNode (org.apache.calcite.rex.RexNode)1 ColumnInfo (org.apache.hadoop.hive.ql.exec.ColumnInfo)1 RowSchema (org.apache.hadoop.hive.ql.exec.RowSchema)1 SelectOperator (org.apache.hadoop.hive.ql.exec.SelectOperator)1 RexVisitor (org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.RexVisitor)1 Schema (org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.Schema)1 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)1 NullOrder (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.NullOrder)1 Order (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.Order)1 OrderSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderSpec)1 PTFInputSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFInputSpec)1 PartitioningSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitioningSpec)1 PTFTranslator (org.apache.hadoop.hive.ql.parse.PTFTranslator)1