Search in sources :

Example 36 with LogicalExpression

use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.

the class ExpressionTreeMaterializer method materializeAndCheckErrors.

public static LogicalExpression materializeAndCheckErrors(LogicalExpression expr, VectorAccessible batch, FunctionLookupContext functionLookupContext) throws SchemaChangeException {
    ErrorCollector collector = new ErrorCollectorImpl();
    LogicalExpression e = ExpressionTreeMaterializer.materialize(expr, batch, collector, functionLookupContext, false, false);
    if (collector.hasErrors()) {
        throw new SchemaChangeException(String.format("Failure while trying to materialize incoming schema.  Errors:\n %s.", collector.toErrorString()));
    }
    return e;
}
Also used : ErrorCollectorImpl(org.apache.drill.common.expression.ErrorCollectorImpl) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) ErrorCollector(org.apache.drill.common.expression.ErrorCollector)

Example 37 with LogicalExpression

use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.

the class ExpressionTreeMaterializer method logFunctionResolutionError.

private static void logFunctionResolutionError(ErrorCollector errorCollector, FunctionCall call) {
    // add error to collector
    StringBuilder sb = new StringBuilder();
    sb.append("Missing function implementation: ");
    sb.append("[");
    sb.append(call.getName());
    sb.append("(");
    boolean first = true;
    for (LogicalExpression e : call.args) {
        TypeProtos.MajorType mt = e.getMajorType();
        if (first) {
            first = false;
        } else {
            sb.append(", ");
        }
        sb.append(mt.getMinorType().name());
        sb.append("-");
        sb.append(mt.getMode().name());
    }
    sb.append(")");
    sb.append("]");
    errorCollector.addGeneralError(call.getPosition(), sb.toString());
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) TypeProtos(org.apache.drill.common.types.TypeProtos)

Example 38 with LogicalExpression

use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.

the class ExpressionTreeMaterializer method convertToNullableType.

public static LogicalExpression convertToNullableType(LogicalExpression fromExpr, MinorType toType, FunctionLookupContext functionLookupContext, ErrorCollector errorCollector) {
    String funcName = "convertToNullable" + toType.toString();
    List<LogicalExpression> args = Lists.newArrayList();
    args.add(fromExpr);
    FunctionCall funcCall = new FunctionCall(funcName, args, ExpressionPosition.UNKNOWN);
    FunctionResolver resolver = FunctionResolverFactory.getResolver(funcCall);
    DrillFuncHolder matchedConvertToNullableFuncHolder = functionLookupContext.findDrillFunction(resolver, funcCall);
    if (matchedConvertToNullableFuncHolder == null) {
        logFunctionResolutionError(errorCollector, funcCall);
        return NullExpression.INSTANCE;
    }
    return matchedConvertToNullableFuncHolder.getExpr(funcName, args, ExpressionPosition.UNKNOWN);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) DrillFuncHolder(org.apache.drill.exec.expr.fn.DrillFuncHolder) QuotedString(org.apache.drill.common.expression.ValueExpressions.QuotedString) FunctionCall(org.apache.drill.common.expression.FunctionCall) FunctionResolver(org.apache.drill.exec.resolver.FunctionResolver)

Example 39 with LogicalExpression

use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.

the class StringCastReturnTypeInference method getType.

/**
 * Defines function return type and sets cast length as type precision
 * if cast length is simple long expression.
 *
 * @param logicalExpressions logical expressions
 * @param attributes function attributes
 * @return return type
 */
@Override
public TypeProtos.MajorType getType(List<LogicalExpression> logicalExpressions, FunctionAttributes attributes) {
    TypeProtos.MajorType.Builder builder = TypeProtos.MajorType.newBuilder().setMinorType(attributes.getReturnValue().getType().getMinorType()).setMode(FunctionUtils.getReturnTypeDataMode(logicalExpressions, attributes));
    LogicalExpression logicalExpression = logicalExpressions.get(1);
    if (logicalExpressions.get(1) instanceof ValueExpressions.LongExpression) {
        long precision = ((ValueExpressions.LongExpression) logicalExpression).getLong();
        builder.setPrecision(Ints.checkedCast(precision));
    }
    return builder.build();
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression)

Example 40 with LogicalExpression

use of org.apache.drill.common.expression.LogicalExpression in project drill by axbaretto.

the class StreamingAggBatch method setupIsSame.

private void setupIsSame(ClassGenerator<StreamingAggregator> cg, LogicalExpression[] keyExprs) {
    cg.setMappingSet(IS_SAME_I1);
    for (final LogicalExpression expr : keyExprs) {
        // first, we rewrite the evaluation stack for each side of the comparison.
        cg.setMappingSet(IS_SAME_I1);
        final HoldingContainer first = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        cg.setMappingSet(IS_SAME_I2);
        final HoldingContainer second = cg.addExpr(expr, ClassGenerator.BlkCreateMode.FALSE);
        final LogicalExpression fh = FunctionGenerationHelper.getOrderingComparatorNullsHigh(first, second, context.getFunctionRegistry());
        final 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)

Aggregations

LogicalExpression (org.apache.drill.common.expression.LogicalExpression)287 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)78 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)77 FunctionCall (org.apache.drill.common.expression.FunctionCall)44 SchemaPath (org.apache.drill.common.expression.SchemaPath)43 HoldingContainer (org.apache.drill.exec.expr.ClassGenerator.HoldingContainer)42 FieldReference (org.apache.drill.common.expression.FieldReference)39 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)38 RexNode (org.apache.calcite.rex.RexNode)32 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)31 DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)30 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)30 ArrayList (java.util.ArrayList)29 MaterializedField (org.apache.drill.exec.record.MaterializedField)28 JConditional (com.sun.codemodel.JConditional)26 ValueExpressions (org.apache.drill.common.expression.ValueExpressions)23 Ordering (org.apache.drill.common.logical.data.Order.Ordering)23 ValueVector (org.apache.drill.exec.vector.ValueVector)22 Test (org.junit.Test)22 TypeProtos (org.apache.drill.common.types.TypeProtos)20