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());
}
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;
}
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());
}
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());
}
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);
}
Aggregations