Search in sources :

Example 1 with TypedNullConstant

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

the class ExpressionTreeMaterializerTest method testMaterializingLateboundTreeValidated.

@Test
public void testMaterializingLateboundTreeValidated() throws SchemaChangeException {
    final RecordBatch batch = mock(RecordBatch.class);
    when(batch.getValueVectorId(new SchemaPath("test", ExpressionPosition.UNKNOWN))).thenReturn(new TypedFieldId(Types.required(MinorType.BIGINT), -5));
    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;
        }
    };
    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 : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) FieldReference(org.apache.drill.common.expression.FieldReference) SchemaPath(org.apache.drill.common.expression.SchemaPath) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) ErrorCollector(org.apache.drill.common.expression.ErrorCollector) TypedNullConstant(org.apache.drill.common.expression.TypedNullConstant) FunctionCall(org.apache.drill.common.expression.FunctionCall) Range(com.google.common.collect.Range) ExpressionPosition(org.apache.drill.common.expression.ExpressionPosition) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest)

Example 2 with TypedNullConstant

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

the class MergeJoinBatch method materializeExpression.

private LogicalExpression materializeExpression(LogicalExpression expression, IterOutcome lastStatus, VectorAccessible input, ErrorCollector collector) {
    LogicalExpression materializedExpr;
    if (lastStatus != IterOutcome.NONE) {
        materializedExpr = ExpressionTreeMaterializer.materialize(expression, input, collector, context.getFunctionRegistry(), unionTypeEnabled);
    } else {
        materializedExpr = new TypedNullConstant(Types.optional(MinorType.INT));
    }
    collector.reportErrors(logger);
    return materializedExpr;
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) TypedNullConstant(org.apache.drill.common.expression.TypedNullConstant)

Example 3 with TypedNullConstant

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

the class ExpressionTreeMaterializerTest method testMaterializingLateboundTreeValidated.

@Test
public void testMaterializingLateboundTreeValidated() throws SchemaChangeException {
    final RecordBatch batch = mock(RecordBatch.class);
    TypedFieldId fieldId = new TypedFieldId.Builder().finalType(Types.required(MinorType.BIGINT)).addId(-5).build();
    when(batch.getValueVectorId(new SchemaPath("test", ExpressionPosition.UNKNOWN))).thenReturn(fieldId);
    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;
        }

        @Override
        public void reportErrors(Logger logger) {
            throw UserException.internalError(null).message("Code generation found %d errors", errorCount).build(logger);
        }
    };
    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());
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) MajorType(org.apache.drill.common.types.TypeProtos.MajorType) ErrorCollector(org.apache.drill.common.expression.ErrorCollector) TypedNullConstant(org.apache.drill.common.expression.TypedNullConstant) Range(org.apache.drill.shaded.guava.com.google.common.collect.Range) Logger(org.slf4j.Logger) 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) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test) VectorTest(org.apache.drill.categories.VectorTest)

Example 4 with TypedNullConstant

use of org.apache.drill.common.expression.TypedNullConstant 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 5 with TypedNullConstant

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

the class TestSimpleFunctions method testHashFunctionResolution.

@Test
public void testHashFunctionResolution() throws JClassAlreadyExistsException, IOException {
    @SuppressWarnings("resource") final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    // test required vs nullable Int input
    resolveHash(new TypedNullConstant(Types.optional(TypeProtos.MinorType.INT)), TypeProtos.DataMode.OPTIONAL, registry);
    resolveHash(new ValueExpressions.IntExpression(1, ExpressionPosition.UNKNOWN), TypeProtos.DataMode.REQUIRED, registry);
    // test required vs nullable float input
    resolveHash(new TypedNullConstant(Types.optional(TypeProtos.MinorType.FLOAT4)), TypeProtos.DataMode.OPTIONAL, registry);
    resolveHash(new ValueExpressions.FloatExpression(5.0f, ExpressionPosition.UNKNOWN), TypeProtos.DataMode.REQUIRED, registry);
    // test required vs nullable long input
    resolveHash(new TypedNullConstant(Types.optional(TypeProtos.MinorType.BIGINT)), TypeProtos.DataMode.OPTIONAL, registry);
    resolveHash(new ValueExpressions.LongExpression(100L, ExpressionPosition.UNKNOWN), TypeProtos.DataMode.REQUIRED, registry);
    // test required vs nullable double input
    resolveHash(new TypedNullConstant(Types.optional(TypeProtos.MinorType.FLOAT8)), TypeProtos.DataMode.OPTIONAL, registry);
    resolveHash(new ValueExpressions.DoubleExpression(100.0, ExpressionPosition.UNKNOWN), TypeProtos.DataMode.REQUIRED, registry);
}
Also used : ValueExpressions(org.apache.drill.common.expression.ValueExpressions) TypedNullConstant(org.apache.drill.common.expression.TypedNullConstant) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

TypedNullConstant (org.apache.drill.common.expression.TypedNullConstant)6 ExecTest (org.apache.drill.exec.ExecTest)5 Test (org.junit.Test)5 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)4 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)3 ExpressionPosition (org.apache.drill.common.expression.ExpressionPosition)3 FieldReference (org.apache.drill.common.expression.FieldReference)3 FunctionCall (org.apache.drill.common.expression.FunctionCall)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)3 Range (com.google.common.collect.Range)2 VectorTest (org.apache.drill.categories.VectorTest)2 ValueExpressions (org.apache.drill.common.expression.ValueExpressions)2 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)2 MockUp (mockit.MockUp)1 NonStrictExpectations (mockit.NonStrictExpectations)1 Range (org.apache.drill.shaded.guava.com.google.common.collect.Range)1 Logger (org.slf4j.Logger)1