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;
}
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;
}
}
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;
}
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();
}
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;
}
Aggregations