Search in sources :

Example 6 with OrderExpression

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

the class ExprNodeConverter method getPSpec.

private PartitioningSpec getPSpec(RexWindow window) {
    PartitioningSpec partitioning = new PartitioningSpec();
    Schema schema = new Schema(tabAlias, inputRowType.getFieldList());
    if (window.partitionKeys != null && !window.partitionKeys.isEmpty()) {
        PartitionSpec pSpec = new PartitionSpec();
        for (RexNode pk : window.partitionKeys) {
            PartitionExpression exprSpec = new PartitionExpression();
            ASTNode astNode = pk.accept(new RexVisitor(schema));
            exprSpec.setExpression(astNode);
            pSpec.addExpression(exprSpec);
        }
        partitioning.setPartSpec(pSpec);
    }
    if (window.orderKeys != null && !window.orderKeys.isEmpty()) {
        OrderSpec oSpec = new OrderSpec();
        for (RexFieldCollation ok : window.orderKeys) {
            OrderExpression exprSpec = new OrderExpression();
            Order order = ok.getDirection() == RelFieldCollation.Direction.ASCENDING ? Order.ASC : Order.DESC;
            NullOrder nullOrder;
            if (ok.right.contains(SqlKind.NULLS_FIRST)) {
                nullOrder = NullOrder.NULLS_FIRST;
            } else if (ok.right.contains(SqlKind.NULLS_LAST)) {
                nullOrder = NullOrder.NULLS_LAST;
            } else {
                // Default
                nullOrder = ok.getDirection() == RelFieldCollation.Direction.ASCENDING ? NullOrder.NULLS_FIRST : NullOrder.NULLS_LAST;
            }
            exprSpec.setOrder(order);
            exprSpec.setNullOrder(nullOrder);
            ASTNode astNode = ok.left.accept(new RexVisitor(schema));
            exprSpec.setExpression(astNode);
            oSpec.addExpression(exprSpec);
        }
        partitioning.setOrderSpec(oSpec);
    }
    return partitioning;
}
Also used : NullOrder(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.NullOrder) Order(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.Order) OrderSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderSpec) RexVisitor(org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.RexVisitor) PartitionExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression) OrderExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderExpression) Schema(org.apache.hadoop.hive.ql.optimizer.calcite.translator.ASTConverter.Schema) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) NullOrder(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.NullOrder) PartitionSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionSpec) RexFieldCollation(org.apache.calcite.rex.RexFieldCollation) PartitioningSpec(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitioningSpec) RexNode(org.apache.calcite.rex.RexNode)

Example 7 with OrderExpression

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

the class PTFTranslator method translate.

private OrderDef translate(ShapeDetails inpShape, OrderSpec spec, PartitionDef partitionDef) throws SemanticException {
    OrderDef def = new OrderDef();
    if (null == spec) {
        return def;
    }
    for (OrderExpression oExpr : spec.getExpressions()) {
        OrderExpressionDef oexpDef = translate(inpShape, oExpr);
        def.addExpression(oexpDef);
    }
    return def;
}
Also used : OrderExpression(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderExpression) OrderDef(org.apache.hadoop.hive.ql.plan.ptf.OrderDef) OrderExpressionDef(org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef)

Aggregations

OrderExpression (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderExpression)7 PartitionExpression (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PartitionExpression)4 ArrayList (java.util.ArrayList)3 SQLCheckConstraint (org.apache.hadoop.hive.metastore.api.SQLCheckConstraint)2 SQLDefaultConstraint (org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint)2 SQLNotNullConstraint (org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)2 SQLUniqueConstraint (org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint)2 CheckConstraint (org.apache.hadoop.hive.ql.metadata.CheckConstraint)2 DefaultConstraint (org.apache.hadoop.hive.ql.metadata.DefaultConstraint)2 NotNullConstraint (org.apache.hadoop.hive.ql.metadata.NotNullConstraint)2 OrderSpec (org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.OrderSpec)2 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)2 OrderDef (org.apache.hadoop.hive.ql.plan.ptf.OrderDef)2 OrderExpressionDef (org.apache.hadoop.hive.ql.plan.ptf.OrderExpressionDef)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 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1