Search in sources :

Example 6 with PartitionSpec

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

the class PTFTranslator method componentize.

public static ArrayList<PTFInvocationSpec> componentize(PTFInvocationSpec ptfInvocation) throws SemanticException {
    ArrayList<PTFInvocationSpec> componentInvocations = new ArrayList<PTFInvocationSpec>();
    Stack<PTFInputSpec> ptfChain = new Stack<PTFInvocationSpec.PTFInputSpec>();
    PTFInputSpec spec = ptfInvocation.getFunction();
    while (spec instanceof PartitionedTableFunctionSpec) {
        ptfChain.push(spec);
        spec = spec.getInput();
    }
    PartitionedTableFunctionSpec prevFn = (PartitionedTableFunctionSpec) ptfChain.pop();
    applyConstantPartition(prevFn);
    PartitionSpec partSpec = prevFn.getPartition();
    OrderSpec orderSpec = prevFn.getOrder();
    if (partSpec == null) {
        // oops this should have been caught before trying to componentize
        throw new SemanticException("No Partitioning specification specified at start of a PTFChain");
    }
    if (orderSpec == null) {
        orderSpec = new OrderSpec(partSpec);
        prevFn.setOrder(orderSpec);
    }
    while (!ptfChain.isEmpty()) {
        PartitionedTableFunctionSpec currentFn = (PartitionedTableFunctionSpec) ptfChain.pop();
        String fnName = currentFn.getName();
        if (!FunctionRegistry.isTableFunction(fnName)) {
            throw new SemanticException(ErrorMsg.INVALID_FUNCTION.getMsg(fnName));
        }
        boolean transformsRawInput = FunctionRegistry.getTableFunctionResolver(fnName).transformsRawInput();
        /*
       * if the current table function has no partition info specified: inherit it from the PTF up
       * the chain.
       */
        if (currentFn.getPartition() == null) {
            currentFn.setPartition(prevFn.getPartition());
            if (currentFn.getOrder() == null) {
                currentFn.setOrder(prevFn.getOrder());
            }
        }
        /*
       * If the current table function has no order info specified;
       */
        if (currentFn.getOrder() == null) {
            currentFn.setOrder(new OrderSpec(currentFn.getPartition()));
        }
        if (!currentFn.getPartition().equals(partSpec) || !currentFn.getOrder().equals(orderSpec) || transformsRawInput) {
            PTFInvocationSpec component = new PTFInvocationSpec();
            component.setFunction(prevFn);
            componentInvocations.add(component);
            PTFQueryInputSpec cQInSpec = new PTFQueryInputSpec();
            cQInSpec.setType(PTFQueryInputType.PTFCOMPONENT);
            currentFn.setInput(cQInSpec);
        }
        prevFn = currentFn;
        partSpec = prevFn.getPartition();
        orderSpec = prevFn.getOrder();
    }
    componentInvocations.add(ptfInvocation);
    return componentInvocations;
}
Also used : ArrayList(java.util.ArrayList) PartitionedTableFunctionSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionedTableFunctionSpec) PTFQueryInputSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFQueryInputSpec) PartitionSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionSpec) Stack(java.util.Stack) PTFInputSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFInputSpec) OrderSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderSpec)

Aggregations

PartitionSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionSpec)6 PartitionExpression (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression)4 OrderSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderSpec)3 CommonToken (org.antlr.runtime.CommonToken)2 PTFInputSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFInputSpec)2 PartitioningSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitioningSpec)2 ArrayList (java.util.ArrayList)1 Stack (java.util.Stack)1 RexFieldCollation (org.apache.calcite.rex.RexFieldCollation)1 RexNode (org.apache.calcite.rex.RexNode)1 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)1 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)1 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)1 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)1 Node (org.apache.hadoop.hive.ql.lib.Node)1 DefaultConstraint (org.apache.hadoop.hive.ql.metadata.DefaultConstraint)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