Search in sources :

Example 61 with RelFieldCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project drill by axbaretto.

the class DrillSortRel method implement.

@Override
public LogicalOperator implement(DrillImplementor implementor) {
    final Order.Builder builder = Order.builder();
    builder.setInput(implementor.visitChild(this, 0, getInput()));
    final List<String> childFields = getInput().getRowType().getFieldNames();
    for (RelFieldCollation fieldCollation : this.collation.getFieldCollations()) {
        builder.addOrdering(fieldCollation.getDirection(), new FieldReference(childFields.get(fieldCollation.getFieldIndex())), fieldCollation.nullDirection);
    }
    return builder.build();
}
Also used : Order(org.apache.drill.common.logical.data.Order) FieldReference(org.apache.drill.common.expression.FieldReference) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation)

Example 62 with RelFieldCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project drill by axbaretto.

the class WindowPrule method getDistributionFieldsFromCollation.

private List<DistributionField> getDistributionFieldsFromCollation(Window.Group window) {
    List<DistributionField> distFields = Lists.newArrayList();
    for (RelFieldCollation relField : window.collation().getFieldCollations()) {
        DistributionField field = new DistributionField(relField.getFieldIndex());
        distFields.add(field);
    }
    return distFields;
}
Also used : RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) DistributionField(org.apache.drill.exec.planner.physical.DrillDistributionTrait.DistributionField)

Example 63 with RelFieldCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project hive by apache.

the class ASTConverter method convertSortToASTNode.

private void convertSortToASTNode(HiveSortExchange hiveSortExchange) {
    List<RelFieldCollation> fieldCollations = hiveSortExchange.getCollation().getFieldCollations();
    convertFieldCollationsToASTNode(hiveSortExchange, new Schema(hiveSortExchange), fieldCollations, null, HiveParser.TOK_SORTBY, "TOK_SORTBY");
}
Also used : FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation)

Example 64 with RelFieldCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project hive by apache.

the class ASTConverter method convertOrderLimitToASTNode.

private void convertOrderLimitToASTNode(HiveSortLimit hiveSortLimit) {
    List<RelFieldCollation> fieldCollations = hiveSortLimit.getCollation().getFieldCollations();
    convertFieldCollationsToASTNode(hiveSortLimit, new Schema(hiveSortLimit), fieldCollations, hiveSortLimit.getInputRefToCallMap(), HiveParser.TOK_ORDERBY, "TOK_ORDERBY");
    RexNode offsetExpr = hiveSortLimit.getOffsetExpr();
    RexNode fetchExpr = hiveSortLimit.getFetchExpr();
    if (fetchExpr != null) {
        Object offset = (offsetExpr == null) ? Integer.valueOf(0) : ((RexLiteral) offsetExpr).getValue2();
        Object fetch = ((RexLiteral) fetchExpr).getValue2();
        hiveAST.limit = ASTBuilder.limit(offset, fetch);
    }
}
Also used : RexLiteral(org.apache.calcite.rex.RexLiteral) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) RexNode(org.apache.calcite.rex.RexNode)

Example 65 with RelFieldCollation

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelFieldCollation in project hive by apache.

the class HiveJdbcImplementor method visit.

@Override
public Result visit(Sort e) {
    Result x = visitInput(e, 0, Clause.ORDER_BY, Clause.FETCH, Clause.OFFSET);
    Builder builder = x.builder(e);
    List<SqlNode> orderByList = Expressions.list();
    for (RelFieldCollation field : e.getCollation().getFieldCollations()) {
        builder.addOrderItem(orderByList, field);
    }
    // Create select list as we want to keep the column aliases
    // instead of producing STAR
    final List<SqlNode> selectList = new ArrayList<>();
    for (int i = 0; i < e.getRowType().getFieldCount(); i++) {
        RexInputRef ref = RexInputRef.of(i, e.getRowType());
        SqlNode sqlExpr = builder.context.toSql(null, ref);
        addSelect(selectList, sqlExpr, e.getRowType());
    }
    builder.setSelect(new SqlNodeList(selectList, POS));
    if (!orderByList.isEmpty()) {
        builder.setOrderBy(new SqlNodeList(orderByList, POS));
        x = builder.result();
    }
    if (e.fetch != null) {
        builder = x.builder(e);
        builder.setFetch(builder.context.toSql(null, e.fetch));
        x = builder.result();
    }
    if (e.offset != null) {
        builder = x.builder(e);
        builder.setOffset(builder.context.toSql(null, e.offset));
        x = builder.result();
    }
    return x;
}
Also used : RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) ArrayList(java.util.ArrayList) RexInputRef(org.apache.calcite.rex.RexInputRef) SqlNodeList(org.apache.calcite.sql.SqlNodeList) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)101 ArrayList (java.util.ArrayList)36 RexNode (org.apache.calcite.rex.RexNode)36 RelCollation (org.apache.calcite.rel.RelCollation)33 RelNode (org.apache.calcite.rel.RelNode)28 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)17 RexInputRef (org.apache.calcite.rex.RexInputRef)17 RelDataType (org.apache.calcite.rel.type.RelDataType)14 ImmutableList (com.google.common.collect.ImmutableList)13 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)13 Sort (org.apache.calcite.rel.core.Sort)12 RelTraitSet (org.apache.calcite.plan.RelTraitSet)11 RexCall (org.apache.calcite.rex.RexCall)11 RexLiteral (org.apache.calcite.rex.RexLiteral)11 Project (org.apache.calcite.rel.core.Project)9 FieldReference (org.apache.drill.common.expression.FieldReference)9 HashMap (java.util.HashMap)8 RelOptCluster (org.apache.calcite.plan.RelOptCluster)8 Map (java.util.Map)7 AggregateCall (org.apache.calcite.rel.core.AggregateCall)7