Search in sources :

Example 1 with WindowPOP

use of org.apache.drill.exec.physical.config.WindowPOP in project drill by axbaretto.

the class WindowPrel method getPhysicalOperator.

@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
    Prel child = (Prel) this.getInput();
    PhysicalOperator childPOP = child.getPhysicalOperator(creator);
    final List<String> childFields = getInput().getRowType().getFieldNames();
    // We don't support distinct partitions
    checkState(groups.size() == 1, "Only one window is expected in WindowPrel");
    Group window = groups.get(0);
    List<NamedExpression> withins = Lists.newArrayList();
    List<NamedExpression> aggs = Lists.newArrayList();
    List<Order.Ordering> orderings = Lists.newArrayList();
    for (int group : BitSets.toIter(window.keys)) {
        FieldReference fr = new FieldReference(childFields.get(group), ExpressionPosition.UNKNOWN);
        withins.add(new NamedExpression(fr, fr));
    }
    for (AggregateCall aggCall : window.getAggregateCalls(this)) {
        FieldReference ref = new FieldReference(aggCall.getName());
        LogicalExpression expr = toDrill(aggCall, childFields);
        aggs.add(new NamedExpression(expr, ref));
    }
    for (RelFieldCollation fieldCollation : window.orderKeys.getFieldCollations()) {
        orderings.add(new Order.Ordering(fieldCollation.getDirection(), new FieldReference(childFields.get(fieldCollation.getFieldIndex())), fieldCollation.nullDirection));
    }
    WindowPOP windowPOP = new WindowPOP(childPOP, withins, aggs, orderings, window.isRows, WindowPOP.newBound(window.lowerBound), WindowPOP.newBound(window.upperBound));
    creator.addMetadata(this, windowPOP);
    return windowPOP;
}
Also used : Order(org.apache.drill.common.logical.data.Order) FieldReference(org.apache.drill.common.expression.FieldReference) WindowPOP(org.apache.drill.exec.physical.config.WindowPOP) AggregateCall(org.apache.calcite.rel.core.AggregateCall) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) NamedExpression(org.apache.drill.common.logical.data.NamedExpression) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation)

Example 2 with WindowPOP

use of org.apache.drill.exec.physical.config.WindowPOP in project drill by apache.

the class WindowPrel method getPhysicalOperator.

@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
    Prel child = (Prel) this.getInput();
    PhysicalOperator childPOP = child.getPhysicalOperator(creator);
    final List<String> childFields = getInput().getRowType().getFieldNames();
    // We don't support distinct partitions
    checkState(groups.size() == 1, "Only one window is expected in WindowPrel");
    Group window = groups.get(0);
    List<NamedExpression> withins = Lists.newArrayList();
    List<NamedExpression> aggs = Lists.newArrayList();
    List<Order.Ordering> orderings = Lists.newArrayList();
    for (int group : BitSets.toIter(window.keys)) {
        FieldReference fr = new FieldReference(childFields.get(group), ExpressionPosition.UNKNOWN);
        withins.add(new NamedExpression(fr, fr));
    }
    for (AggregateCall aggCall : window.getAggregateCalls(this)) {
        FieldReference ref = new FieldReference(aggCall.getName());
        LogicalExpression expr = toDrill(aggCall, childFields);
        aggs.add(new NamedExpression(expr, ref));
    }
    for (RelFieldCollation fieldCollation : window.orderKeys.getFieldCollations()) {
        orderings.add(new Order.Ordering(fieldCollation.getDirection(), new FieldReference(childFields.get(fieldCollation.getFieldIndex())), fieldCollation.nullDirection));
    }
    WindowPOP windowPOP = new WindowPOP(childPOP, withins, aggs, orderings, window.isRows, WindowPOP.newBound(window.lowerBound), WindowPOP.newBound(window.upperBound));
    creator.addMetadata(this, windowPOP);
    return windowPOP;
}
Also used : Order(org.apache.drill.common.logical.data.Order) FieldReference(org.apache.drill.common.expression.FieldReference) WindowPOP(org.apache.drill.exec.physical.config.WindowPOP) AggregateCall(org.apache.calcite.rel.core.AggregateCall) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) NamedExpression(org.apache.drill.common.logical.data.NamedExpression) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation)

Aggregations

RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)2 AggregateCall (org.apache.calcite.rel.core.AggregateCall)2 FieldReference (org.apache.drill.common.expression.FieldReference)2 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)2 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)2 Order (org.apache.drill.common.logical.data.Order)2 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)2 WindowPOP (org.apache.drill.exec.physical.config.WindowPOP)2