Search in sources :

Example 1 with LogicalOperator

use of org.apache.drill.common.logical.data.LogicalOperator in project drill by apache.

the class DrillFilterRel method implement.

@Override
public LogicalOperator implement(DrillImplementor implementor) {
    final LogicalOperator input = implementor.visitChild(this, 0, getInput());
    org.apache.drill.common.logical.data.Filter f = new org.apache.drill.common.logical.data.Filter(getFilterExpression(implementor.getContext()));
    f.setInput(input);
    return f;
}
Also used : Filter(org.apache.drill.common.logical.data.Filter) Filter(org.apache.drill.common.logical.data.Filter) LogicalOperator(org.apache.drill.common.logical.data.LogicalOperator)

Example 2 with LogicalOperator

use of org.apache.drill.common.logical.data.LogicalOperator in project drill by apache.

the class DrillJoinRel method implementInput.

/**
   * Check to make sure that the fields of the inputs are the same as the output field names.  If not, insert a project renaming them.
   * @param implementor
   * @param i
   * @param offset
   * @param input
   * @return
   */
private LogicalOperator implementInput(DrillImplementor implementor, int i, int offset, RelNode input) {
    final LogicalOperator inputOp = implementor.visitChild(this, i, input);
    assert uniqueFieldNames(input.getRowType());
    final List<String> fields = getRowType().getFieldNames();
    final List<String> inputFields = input.getRowType().getFieldNames();
    final List<String> outputFields = fields.subList(offset, offset + inputFields.size());
    if (!outputFields.equals(inputFields)) {
        // lost.
        return rename(implementor, inputOp, inputFields, outputFields);
    } else {
        return inputOp;
    }
}
Also used : LogicalOperator(org.apache.drill.common.logical.data.LogicalOperator)

Example 3 with LogicalOperator

use of org.apache.drill.common.logical.data.LogicalOperator in project drill by apache.

the class DrillWindowRel method implement.

@Override
public LogicalOperator implement(DrillImplementor implementor) {
    final LogicalOperator inputOp = implementor.visitChild(this, 0, getInput());
    org.apache.drill.common.logical.data.Window.Builder builder = new org.apache.drill.common.logical.data.Window.Builder();
    final List<String> fields = getRowType().getFieldNames();
    final List<String> childFields = getInput().getRowType().getFieldNames();
    for (Group window : groups) {
        for (RelFieldCollation orderKey : window.orderKeys.getFieldCollations()) {
            builder.addOrdering(new Order.Ordering(orderKey.getDirection(), new FieldReference(fields.get(orderKey.getFieldIndex()))));
        }
        for (int group : BitSets.toIter(window.keys)) {
            FieldReference fr = new FieldReference(childFields.get(group), ExpressionPosition.UNKNOWN);
            builder.addWithin(fr, fr);
        }
        int groupCardinality = window.keys.cardinality();
        for (Ord<AggregateCall> aggCall : Ord.zip(window.getAggregateCalls(this))) {
            FieldReference ref = new FieldReference(fields.get(groupCardinality + aggCall.i));
            LogicalExpression expr = toDrill(aggCall.e, childFields);
            builder.addAggregation(ref, expr);
        }
    }
    builder.setInput(inputOp);
    org.apache.drill.common.logical.data.Window frame = builder.build();
    return frame;
}
Also used : Order(org.apache.drill.common.logical.data.Order) FieldReference(org.apache.drill.common.expression.FieldReference) LogicalOperator(org.apache.drill.common.logical.data.LogicalOperator) AggregateCall(org.apache.calcite.rel.core.AggregateCall) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation)

Example 4 with LogicalOperator

use of org.apache.drill.common.logical.data.LogicalOperator in project drill by apache.

the class DrillJoinRel method implement.

@Override
public LogicalOperator implement(DrillImplementor implementor) {
    final List<String> fields = getRowType().getFieldNames();
    assert isUnique(fields);
    final int leftCount = left.getRowType().getFieldCount();
    final List<String> leftFields = fields.subList(0, leftCount);
    final List<String> rightFields = fields.subList(leftCount, fields.size());
    final LogicalOperator leftOp = implementInput(implementor, 0, 0, left);
    final LogicalOperator rightOp = implementInput(implementor, 1, leftCount, right);
    Join.Builder builder = Join.builder();
    builder.type(joinType);
    builder.left(leftOp);
    builder.right(rightOp);
    for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
        builder.addCondition("==", new FieldReference(leftFields.get(pair.left)), new FieldReference(rightFields.get(pair.right)));
    }
    return builder.build();
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) LogicalOperator(org.apache.drill.common.logical.data.LogicalOperator) Join(org.apache.drill.common.logical.data.Join)

Example 5 with LogicalOperator

use of org.apache.drill.common.logical.data.LogicalOperator in project drill by apache.

the class DrillLimitRel method implement.

@Override
public LogicalOperator implement(DrillImplementor implementor) {
    LogicalOperator inputOp = implementor.visitChild(this, 0, getInput());
    // First offset to include into results (inclusive). Null implies it is starting from offset 0
    int first = offset != null ? Math.max(0, RexLiteral.intValue(offset)) : 0;
    // Last offset to stop including into results (exclusive), translating fetch row counts into an offset.
    // Null value implies including entire remaining result set from first offset
    Integer last = fetch != null ? Math.max(0, RexLiteral.intValue(fetch)) + first : null;
    Limit limit = new Limit(first, last);
    limit.setInput(inputOp);
    return limit;
}
Also used : LogicalOperator(org.apache.drill.common.logical.data.LogicalOperator) Limit(org.apache.drill.common.logical.data.Limit)

Aggregations

LogicalOperator (org.apache.drill.common.logical.data.LogicalOperator)7 FieldReference (org.apache.drill.common.expression.FieldReference)2 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)1 Filter (org.apache.drill.common.logical.data.Filter)1 Join (org.apache.drill.common.logical.data.Join)1 Limit (org.apache.drill.common.logical.data.Limit)1 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)1 Order (org.apache.drill.common.logical.data.Order)1 Project (org.apache.drill.common.logical.data.Project)1