Search in sources :

Example 1 with ExpressionPosition

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

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

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

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

the class TestHashAggBatch method createHashAggPhysicalOperator.

private HashAggregate createHashAggPhysicalOperator(AggPrelBase.OperatorPhase phase) {
    final List<NamedExpression> keyExpressions = Lists.newArrayList(new NamedExpression(SchemaPath.getSimplePath(FIRST_NAME_COL), new FieldReference(FIRST_NAME_COL)), new NamedExpression(SchemaPath.getSimplePath(LAST_NAME_COL), new FieldReference(LAST_NAME_COL)));
    final List<NamedExpression> aggExpressions = Lists.newArrayList(new NamedExpression(new FunctionCall("sum", ImmutableList.of(SchemaPath.getSimplePath(STUFF_COL)), new ExpressionPosition(null, 0)), new FieldReference(TOTAL_STUFF_COL)));
    return new HashAggregate(null, phase, keyExpressions, aggExpressions, 0.0f);
}
Also used : FieldReference(org.apache.drill.common.expression.FieldReference) NamedExpression(org.apache.drill.common.logical.data.NamedExpression) FunctionCall(org.apache.drill.common.expression.FunctionCall) ExpressionPosition(org.apache.drill.common.expression.ExpressionPosition) HashAggregate(org.apache.drill.exec.physical.config.HashAggregate)

Aggregations

ExpressionPosition (org.apache.drill.common.expression.ExpressionPosition)4 FieldReference (org.apache.drill.common.expression.FieldReference)4 FunctionCall (org.apache.drill.common.expression.FunctionCall)4 ErrorCollector (org.apache.drill.common.expression.ErrorCollector)3 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 TypedNullConstant (org.apache.drill.common.expression.TypedNullConstant)3 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)3 ExecTest (org.apache.drill.exec.ExecTest)3 Test (org.junit.Test)3 Range (com.google.common.collect.Range)2 VectorTest (org.apache.drill.categories.VectorTest)2 MockUp (mockit.MockUp)1 NonStrictExpectations (mockit.NonStrictExpectations)1 NamedExpression (org.apache.drill.common.logical.data.NamedExpression)1 HashAggregate (org.apache.drill.exec.physical.config.HashAggregate)1 Range (org.apache.drill.shaded.guava.com.google.common.collect.Range)1 Logger (org.slf4j.Logger)1