Search in sources :

Example 26 with HoldingContainer

use of org.apache.drill.exec.expr.ClassGenerator.HoldingContainer in project drill by apache.

the class StreamingAggBatch method setupIsSame.

protected void setupIsSame(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
    cg.setMappingSet(IS_SAME_I1);
    for (LogicalExpression expr : keyExprs) {
        // first, we rewrite the evaluation stack for each side of the comparison.
        cg.setMappingSet(IS_SAME_I1);
        HoldingContainer first = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        cg.setMappingSet(IS_SAME_I2);
        HoldingContainer second = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        LogicalExpression fh = FunctionGenerationHelper.getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
        HoldingContainer out = cg.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
        cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
    }
    cg.getEvalBlock()._return(JExpr.TRUE);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) HoldingContainer(org.apache.drill.exec.expr.ClassGenerator.HoldingContainer)

Example 27 with HoldingContainer

use of org.apache.drill.exec.expr.ClassGenerator.HoldingContainer in project drill by apache.

the class StreamingAggBatch method setupIsSameApart.

protected void setupIsSameApart(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
    cg.setMappingSet(ISA_B1);
    for (LogicalExpression expr : keyExprs) {
        // first, we rewrite the evaluation stack for each side of the comparison.
        cg.setMappingSet(ISA_B1);
        HoldingContainer first = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        cg.setMappingSet(ISA_B2);
        HoldingContainer second = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        LogicalExpression fh = FunctionGenerationHelper.getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
        HoldingContainer out = cg.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
        cg.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)))._then()._return(JExpr.FALSE);
    }
    cg.getEvalBlock()._return(JExpr.TRUE);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) HoldingContainer(org.apache.drill.exec.expr.ClassGenerator.HoldingContainer)

Example 28 with HoldingContainer

use of org.apache.drill.exec.expr.ClassGenerator.HoldingContainer in project drill by apache.

the class MergingRecordBatch method generateComparisons.

private void generateComparisons(final ClassGenerator<?> g, final VectorAccessible batch) throws SchemaChangeException {
    g.setMappingSet(MAIN_MAPPING);
    for (final Ordering od : popConfig.getOrderings()) {
        // first, we rewrite the evaluation stack for each side of the comparison.
        final ErrorCollector collector = new ErrorCollectorImpl();
        final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), batch, collector, context.getFunctionRegistry());
        if (collector.hasErrors()) {
            throw new SchemaChangeException("Failure while materializing expression. " + collector.toErrorString());
        }
        g.setMappingSet(LEFT_MAPPING);
        final HoldingContainer left = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        g.setMappingSet(RIGHT_MAPPING);
        final HoldingContainer right = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        g.setMappingSet(MAIN_MAPPING);
        // next we wrap the two comparison sides and add the expression block for the comparison.
        final LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, context.getFunctionRegistry());
        final HoldingContainer out = g.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
        final JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));
        if (od.getDirection() == Direction.ASCENDING) {
            jc._then()._return(out.getValue());
        } else {
            jc._then()._return(out.getValue().minus());
        }
    }
    g.getEvalBlock()._return(JExpr.lit(0));
}
Also used : ErrorCollectorImpl(org.apache.drill.common.expression.ErrorCollectorImpl) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) HoldingContainer(org.apache.drill.exec.expr.ClassGenerator.HoldingContainer) Ordering(org.apache.drill.common.logical.data.Order.Ordering) ErrorCollector(org.apache.drill.common.expression.ErrorCollector) JConditional(com.sun.codemodel.JConditional)

Example 29 with HoldingContainer

use of org.apache.drill.exec.expr.ClassGenerator.HoldingContainer in project drill by apache.

the class BaseSortWrapper method generateComparisons.

protected void generateComparisons(ClassGenerator<?> g, VectorAccessible batch, org.slf4j.Logger logger) {
    g.setMappingSet(MAIN_MAPPING);
    Sort popConfig = context.getOperatorDefn();
    for (Ordering od : popConfig.getOrderings()) {
        // first, we rewrite the evaluation stack for each side of the comparison.
        ErrorCollector collector = new ErrorCollectorImpl();
        final LogicalExpression expr = ExpressionTreeMaterializer.materialize(od.getExpr(), batch, collector, context.getFragmentContext().getFunctionRegistry());
        if (collector.hasErrors()) {
            throw UserException.unsupportedError().message("Failure while materializing expression. " + collector.toErrorString()).build(logger);
        }
        g.setMappingSet(LEFT_MAPPING);
        HoldingContainer left = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        g.setMappingSet(RIGHT_MAPPING);
        HoldingContainer right = g.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        g.setMappingSet(MAIN_MAPPING);
        // next we wrap the two comparison sides and add the expression block for the comparison.
        LogicalExpression fh = FunctionGenerationHelper.getOrderingComparator(od.nullsSortHigh(), left, right, context.getFragmentContext().getFunctionRegistry());
        HoldingContainer out = g.addExpr(fh, ClassGenerator.BlkCreateMode.FALSE);
        JConditional jc = g.getEvalBlock()._if(out.getValue().ne(JExpr.lit(0)));
        if (od.getDirection() == Direction.ASCENDING) {
            jc._then()._return(out.getValue());
        } else {
            jc._then()._return(out.getValue().minus());
        }
        g.rotateBlock();
    }
    g.rotateBlock();
    g.getEvalBlock()._return(JExpr.lit(0));
}
Also used : ErrorCollectorImpl(org.apache.drill.common.expression.ErrorCollectorImpl) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) HoldingContainer(org.apache.drill.exec.expr.ClassGenerator.HoldingContainer) Ordering(org.apache.drill.common.logical.data.Order.Ordering) Sort(org.apache.drill.exec.physical.config.Sort) ErrorCollector(org.apache.drill.common.expression.ErrorCollector) JConditional(com.sun.codemodel.JConditional)

Example 30 with HoldingContainer

use of org.apache.drill.exec.expr.ClassGenerator.HoldingContainer in project drill by apache.

the class DrillSimpleFuncHolder method renderEnd.

/**
 * Render the various code blocks for a simple function.
 *
 * @param classGenerator code generator
 * @param inputVariables value holder references for each input value. Variables
 * are in the same order as the declared function parameters
 * @param workspaceJVars internal working variables as declared with the
 * <code>@Workspece</code> annotations. These are simple variables, not
 * Drill value holders
 * @param holderExpr the function call expression
 */
@Override
public HoldingContainer renderEnd(ClassGenerator<?> classGenerator, HoldingContainer[] inputVariables, JVar[] workspaceJVars, FunctionHolderExpression holderExpr) {
    // exception.
    for (int i = 0; i < inputVariables.length; i++) {
        if (getAttributeParameter(i).isConstant() && !inputVariables[i].isConstant()) {
            throw new DrillRuntimeException(String.format("The argument '%s' of Function '%s' has to be constant!", getAttributeParameter(i).getName(), this.getRegisteredNames()[0]));
        }
    }
    // Inline code from the function's setup block
    generateBody(classGenerator, BlockType.SETUP, setupBody(), inputVariables, workspaceJVars, true);
    // Generate the wrapper, and inline code for, the function's eval block
    HoldingContainer c = generateEvalBody(classGenerator, inputVariables, evalBody(), workspaceJVars, holderExpr);
    // Generate code for an aggregate functions reset block
    generateBody(classGenerator, BlockType.RESET, resetBody(), null, workspaceJVars, false);
    // Inline code from the function's cleanup() method
    generateBody(classGenerator, BlockType.CLEANUP, cleanupBody(), null, workspaceJVars, false);
    return c;
}
Also used : HoldingContainer(org.apache.drill.exec.expr.ClassGenerator.HoldingContainer) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Aggregations

HoldingContainer (org.apache.drill.exec.expr.ClassGenerator.HoldingContainer)58 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)40 JConditional (com.sun.codemodel.JConditional)29 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)23 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)23 Ordering (org.apache.drill.common.logical.data.Order.Ordering)21 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)14 JVar (com.sun.codemodel.JVar)12 JBlock (com.sun.codemodel.JBlock)9 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)9 HoldingContainerExpression (org.apache.drill.exec.expr.HoldingContainerExpression)7 ValueVectorWriteExpression (org.apache.drill.exec.expr.ValueVectorWriteExpression)6 FunctionCall (org.apache.drill.common.expression.FunctionCall)5 ValueVectorReadExpression (org.apache.drill.exec.expr.ValueVectorReadExpression)5 JExpression (com.sun.codemodel.JExpression)4 MaterializedField (org.apache.drill.exec.record.MaterializedField)4 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)4 ValueVector (org.apache.drill.exec.vector.ValueVector)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3