Search in sources :

Example 86 with LogicalExpression

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

the class TestSimpleFunctions method resolveHash.

public void resolveHash(DrillConfig config, LogicalExpression arg, TypeProtos.MajorType expectedArg, TypeProtos.MajorType expectedOut, TypeProtos.DataMode expectedBestInputMode, FunctionImplementationRegistry registry) throws JClassAlreadyExistsException, IOException {
    final List<LogicalExpression> args = new ArrayList<>();
    args.add(arg);
    FunctionCall call = new FunctionCall("hash", args, ExpressionPosition.UNKNOWN);
    final FunctionResolver resolver = FunctionResolverFactory.getResolver(call);
    final DrillFuncHolder matchedFuncHolder = registry.findDrillFunction(resolver, call);
    assertEquals(expectedBestInputMode, matchedFuncHolder.getParmMajorType(0).getMode());
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) DrillFuncHolder(org.apache.drill.exec.expr.fn.DrillFuncHolder) ArrayList(java.util.ArrayList) FunctionCall(org.apache.drill.common.expression.FunctionCall) FunctionResolver(org.apache.drill.exec.resolver.FunctionResolver)

Example 87 with LogicalExpression

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

the class ExpressionInterpreterTest method evalExprWithInterpreter.

private ValueVector evalExprWithInterpreter(String expression, RecordBatch batch, Drillbit bit) throws Exception {
    final LogicalExpression expr = parseExpr(expression);
    final ErrorCollector error = new ErrorCollectorImpl();
    final LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, batch, error, bit.getContext().getFunctionImplementationRegistry());
    if (error.getErrorCount() != 0) {
        logger.error("Failure while materializing expression [{}].  Errors: {}", expression, error);
        assertEquals(0, error.getErrorCount());
    }
    final MaterializedField outputField = MaterializedField.create("outCol", materializedExpr.getMajorType());
    final ValueVector vector = TypeHelper.getNewVector(outputField, bit.getContext().getAllocator());
    vector.allocateNewSafe();
    InterpreterEvaluator.evaluate(batch, vector, materializedExpr);
    return vector;
}
Also used : ErrorCollectorImpl(org.apache.drill.common.expression.ErrorCollectorImpl) ValueVector(org.apache.drill.exec.vector.ValueVector) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ErrorCollector(org.apache.drill.common.expression.ErrorCollector) MaterializedField(org.apache.drill.exec.record.MaterializedField)

Example 88 with LogicalExpression

use of org.apache.drill.common.expression.LogicalExpression 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());
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) ErrorCollector(org.apache.drill.common.expression.ErrorCollector) MockUp(mockit.MockUp) TypedNullConstant(org.apache.drill.common.expression.TypedNullConstant) Range(com.google.common.collect.Range) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) SchemaPath(org.apache.drill.common.expression.SchemaPath) FunctionCall(org.apache.drill.common.expression.FunctionCall) ExpressionPosition(org.apache.drill.common.expression.ExpressionPosition) NonStrictExpectations(mockit.NonStrictExpectations) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Example 89 with LogicalExpression

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

the class ConditionalExprOptimizer method visitIfExpression.

@Override
public LogicalExpression visitIfExpression(IfExpression ifExpr, Void value) throws RuntimeException {
    LogicalExpression newElseExpr = ifExpr.elseExpression.accept(this, value);
    IfCondition conditions = ifExpr.ifCondition;
    LogicalExpression newCondition = conditions.condition.accept(this, value);
    LogicalExpression newExpr = conditions.expression.accept(this, value);
    conditions = new IfExpression.IfCondition(newCondition, newExpr);
    return IfExpression.newBuilder().setElse(newElseExpr).setIfCondition(conditions).build();
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) IfExpression(org.apache.drill.common.expression.IfExpression) IfCondition(org.apache.drill.common.expression.IfExpression.IfCondition) IfCondition(org.apache.drill.common.expression.IfExpression.IfCondition)

Example 90 with LogicalExpression

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

the class TreeTest method testExpressionParsing.

/**
   * Attempt to parse an expression.  Once parsed, convert it to a string and then parse it again to make sure serialization works.
   * @param expr
   * @throws RecognitionException
   * @throws IOException
   */
private void testExpressionParsing(String expr) throws RecognitionException, IOException {
    logger.debug("-----" + expr + "-----");
    LogicalExpression e = parseExpression(expr);
    String newStringExpr = serializeExpression(e);
    logger.debug(newStringExpr);
    LogicalExpression e2 = parseExpression(newStringExpr);
//Assert.assertEquals(e, e2);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression)

Aggregations

LogicalExpression (org.apache.drill.common.expression.LogicalExpression)90 ErrorCollectorImpl (org.apache.drill.common.expression.ErrorCollectorImpl)32 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)31 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)18 HoldingContainer (org.apache.drill.exec.expr.ClassGenerator.HoldingContainer)17 FieldReference (org.apache.drill.common.expression.FieldReference)14 FunctionCall (org.apache.drill.common.expression.FunctionCall)14 SchemaPath (org.apache.drill.common.expression.SchemaPath)12 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)11 MaterializedField (org.apache.drill.exec.record.MaterializedField)11 JConditional (com.sun.codemodel.JConditional)10 TypedFieldId (org.apache.drill.exec.record.TypedFieldId)10 ValueVector (org.apache.drill.exec.vector.ValueVector)10 IOException (java.io.IOException)9 Ordering (org.apache.drill.common.logical.data.Order.Ordering)9 DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)9 ValueExpressions (org.apache.drill.common.expression.ValueExpressions)8 QuotedString (org.apache.drill.common.expression.ValueExpressions.QuotedString)8 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)8 ArrayList (java.util.ArrayList)7