use of org.apache.drill.common.expression.FieldReference 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;
}
use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class WindowPrel method toDrill.
protected LogicalExpression toDrill(AggregateCall call, List<String> fn) {
DrillParseContext context = new DrillParseContext(PrelUtil.getSettings(getCluster()));
List<LogicalExpression> args = Lists.newArrayList();
for (Integer i : call.getArgList()) {
final int indexInConstants = i - fn.size();
if (i < fn.size()) {
args.add(new FieldReference(fn.get(i)));
} else {
final RexLiteral constant = constants.get(indexInConstants);
LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), constant);
args.add(expr);
}
}
// for count(1).
if (args.isEmpty()) {
args.add(new ValueExpressions.LongExpression(1l));
}
return new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN);
}
use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class DrillComplexWriterFuncHolder method generateEvalBody.
@Override
protected HoldingContainer generateEvalBody(ClassGenerator<?> classGenerator, HoldingContainer[] inputVariables, String body, JVar[] workspaceJVars, FunctionHolderExpression holderExpr) {
FieldReference fieldReference = holderExpr.getFieldReference();
classGenerator.getEvalBlock().directStatement(String.format("//---- start of eval portion of %s function. ----//", getRegisteredNames()[0]));
JBlock sub = new JBlock(true, true);
JBlock topSub = sub;
JVar complexWriter = classGenerator.declareClassField("complexWriter", classGenerator.getModel()._ref(ComplexWriter.class));
JInvocation container = classGenerator.getMappingSet().getOutgoing().invoke("getOutgoingContainer");
// Default name is "col", if not passed in a reference name for the output vector.
String refName = fieldReference == null ? "col" : fieldReference.getRootSegment().getPath();
JClass cwClass = classGenerator.getModel().ref(VectorAccessibleComplexWriter.class);
classGenerator.getSetupBlock().assign(complexWriter, cwClass.staticInvoke("getWriter").arg(refName).arg(container));
JClass projBatchClass = classGenerator.getModel().ref(ProjectRecordBatch.class);
JExpression projBatch = JExpr.cast(projBatchClass, classGenerator.getMappingSet().getOutgoing());
classGenerator.getSetupBlock().add(projBatch.invoke("addComplexWriter").arg(complexWriter));
classGenerator.getEvalBlock().add(complexWriter.invoke("setPosition").arg(classGenerator.getMappingSet().getValueWriteIndex()));
sub.decl(classGenerator.getModel()._ref(ComplexWriter.class), getReturnValue().getName(), complexWriter);
// add the subblock after the out declaration.
classGenerator.getEvalBlock().add(topSub);
addProtectedBlock(classGenerator, sub, body, inputVariables, workspaceJVars, false);
// JConditional jc = classGenerator.getEvalBlock()._if(complexWriter.invoke("ok").not());
// jc._then().add(complexWriter.invoke("reset"));
// jc._then().directStatement("System.out.println(\"debug : write ok fail!, inIndex = \" + inIndex);");
// jc._then()._return(JExpr.FALSE);
// jc._else().directStatement("System.out.println(\"debug : write successful, inIndex = \" + inIndex);");
classGenerator.getEvalBlock().directStatement(String.format("//---- end of eval portion of %s function. ----//", getRegisteredNames()[0]));
return null;
}
use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class ProjectBatchBuilder method addTransferField.
@Override
public void addTransferField(String name, ValueVector vvIn) {
FieldReference ref = new FieldReference(name);
ValueVector vvOut = container.addOrGet(MaterializedField.create(ref.getAsNamePart().getName(), vvIn.getField().getType()), callBack);
projectBatch.memoryManager.addTransferField(vvIn, vvIn.getField().getName(), vvOut.getField().getName());
transfers.add(vvIn.makeTransferPair(vvOut));
}
use of org.apache.drill.common.expression.FieldReference in project drill by apache.
the class ProjectionMaterializer method setupDirectTransfer.
private void setupDirectTransfer(NamedExpression namedExpression, LogicalExpression expr) {
FieldReference ref = getRef(namedExpression);
int fid = batchBuilder.addDirectTransfer(ref, (ValueVectorReadExpression) expr);
transferFieldIds.add(fid);
}
Aggregations