Search in sources :

Example 76 with FieldReference

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;
}
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 77 with FieldReference

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);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RexLiteral(org.apache.calcite.rex.RexLiteral) FieldReference(org.apache.drill.common.expression.FieldReference) ValueExpressions(org.apache.drill.common.expression.ValueExpressions) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) FunctionCall(org.apache.drill.common.expression.FunctionCall)

Example 78 with FieldReference

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;
}
Also used : ComplexWriter(org.apache.drill.exec.vector.complex.writer.BaseWriter.ComplexWriter) VectorAccessibleComplexWriter(org.apache.drill.exec.record.VectorAccessibleComplexWriter) FieldReference(org.apache.drill.common.expression.FieldReference) JClass(com.sun.codemodel.JClass) JBlock(com.sun.codemodel.JBlock) JInvocation(com.sun.codemodel.JInvocation) JExpression(com.sun.codemodel.JExpression) JVar(com.sun.codemodel.JVar)

Example 79 with FieldReference

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));
}
Also used : ValueVector(org.apache.drill.exec.vector.ValueVector) FieldReference(org.apache.drill.common.expression.FieldReference)

Example 80 with FieldReference

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);
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference)

Aggregations

FieldReference (org.apache.drill.common.expression.FieldReference)84 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)38 Test (org.junit.Test)22 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)19 FunctionCall (org.apache.drill.common.expression.FunctionCall)16 SchemaPath (org.apache.drill.common.expression.SchemaPath)14 Ordering (org.apache.drill.common.logical.data.Order.Ordering)14 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)13 ArrayList (java.util.ArrayList)12 ValueExpressions (org.apache.drill.common.expression.ValueExpressions)12 MaterializedField (org.apache.drill.exec.record.MaterializedField)12 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)10 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)9 Order (org.apache.drill.common.logical.data.Order)9 ExecTest (org.apache.drill.exec.ExecTest)9 AggregateCall (org.apache.calcite.rel.core.AggregateCall)8 OperatorTest (org.apache.drill.categories.OperatorTest)8 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)8 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)7 VectorTest (org.apache.drill.categories.VectorTest)6