use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class ExpressionTreeMaterializerTest method testMaterializingLateboundTreeValidated.
@Test
public void testMaterializingLateboundTreeValidated(@Injectable final RecordBatch batch) throws SchemaChangeException {
ErrorCollector ec = new ErrorCollector() {
int errorCount = 0;
@Override
public void addGeneralError(ExpressionPosition expr, String s) {
errorCount++;
}
@Override
public void addUnexpectedArgumentType(ExpressionPosition expr, String name, MajorType actual, MajorType[] expected, int argumentIndex) {
errorCount++;
}
@Override
public void addUnexpectedArgumentCount(ExpressionPosition expr, int actual, Range<Integer> expected) {
errorCount++;
}
@Override
public void addUnexpectedArgumentCount(ExpressionPosition expr, int actual, int expected) {
errorCount++;
}
@Override
public void addNonNumericType(ExpressionPosition expr, MajorType actual) {
errorCount++;
}
@Override
public void addUnexpectedType(ExpressionPosition expr, int index, MajorType actual) {
errorCount++;
}
@Override
public void addExpectedConstantValue(ExpressionPosition expr, int actual, String s) {
errorCount++;
}
@Override
public boolean hasErrors() {
return errorCount > 0;
}
@Override
public String toErrorString() {
return String.format("Found %s errors.", errorCount);
}
@Override
public int getErrorCount() {
return errorCount;
}
};
new NonStrictExpectations() {
{
batch.getValueVectorId(new SchemaPath("test", ExpressionPosition.UNKNOWN));
result = new TypedFieldId(Types.required(MinorType.BIGINT), -5);
}
};
new MockUp<RemoteFunctionRegistry>() {
@Mock
long getRegistryVersion() {
return 0L;
}
};
LogicalExpression functionCallExpr = new FunctionCall("testFunc", ImmutableList.of((LogicalExpression) new FieldReference("test", ExpressionPosition.UNKNOWN)), ExpressionPosition.UNKNOWN);
LogicalExpression newExpr = ExpressionTreeMaterializer.materialize(functionCallExpr, batch, ec, registry);
assertTrue(newExpr instanceof TypedNullConstant);
assertEquals(1, ec.getErrorCount());
System.out.println(ec.toErrorString());
}
use of org.apache.drill.common.expression.FieldReference in project drill by axbaretto.
the class AggPrelBase method createKeysAndExprs.
protected void createKeysAndExprs() {
final List<String> childFields = getInput().getRowType().getFieldNames();
final List<String> fields = getRowType().getFieldNames();
for (int group : BitSets.toIter(groupSet)) {
FieldReference fr = FieldReference.getWithQuotedRef(childFields.get(group));
keys.add(new NamedExpression(fr, fr));
}
for (Ord<AggregateCall> aggCall : Ord.zip(aggCalls)) {
int aggExprOrdinal = groupSet.cardinality() + aggCall.i;
FieldReference ref = FieldReference.getWithQuotedRef(fields.get(aggExprOrdinal));
LogicalExpression expr = toDrill(aggCall.e, childFields);
NamedExpression ne = new NamedExpression(expr, ref);
aggExprs.add(ne);
if (getOperatorPhase() == OperatorPhase.PHASE_1of2) {
if (aggCall.e.getAggregation().getName().equals("COUNT")) {
// If we are doing a COUNT aggregate in Phase1of2, then in Phase2of2 we should SUM the COUNTs,
SqlAggFunction sumAggFun = new SqlSumCountAggFunction(aggCall.e.getType());
AggregateCall newAggCall = AggregateCall.create(sumAggFun, aggCall.e.isDistinct(), aggCall.e.isApproximate(), Collections.singletonList(aggExprOrdinal), aggCall.e.filterArg, aggCall.e.getType(), aggCall.e.getName());
phase2AggCallList.add(newAggCall);
} else {
AggregateCall newAggCall = AggregateCall.create(aggCall.e.getAggregation(), aggCall.e.isDistinct(), aggCall.e.isApproximate(), Collections.singletonList(aggExprOrdinal), aggCall.e.filterArg, aggCall.e.getType(), aggCall.e.getName());
phase2AggCallList.add(newAggCall);
}
}
}
}
use of org.apache.drill.common.expression.FieldReference in project drill by axbaretto.
the class PrelUtil method getOrdering.
public static List<Ordering> getOrdering(RelCollation collation, RelDataType rowType) {
List<Ordering> orderExpr = Lists.newArrayList();
final List<String> childFields = rowType.getFieldNames();
for (RelFieldCollation fc : collation.getFieldCollations()) {
FieldReference fr = new FieldReference(childFields.get(fc.getFieldIndex()), ExpressionPosition.UNKNOWN, false);
orderExpr.add(new Ordering(fc.getDirection(), fr, fc.nullDirection));
}
return orderExpr;
}
use of org.apache.drill.common.expression.FieldReference in project drill by axbaretto.
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.expression.FieldReference 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();
}
Aggregations