use of io.trino.sql.relational.CallExpression in project trino by trinodb.
the class TestInCodeGenerator method testInteger.
@Test
public void testInteger() {
List<RowExpression> values = new ArrayList<>();
values.add(constant(Integer.MIN_VALUE, INTEGER));
values.add(constant(Integer.MAX_VALUE, INTEGER));
values.add(constant(3, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(constant(null, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(new CallExpression(functionResolution.getCoercion(DOUBLE, INTEGER), Collections.singletonList(constant(12345678901234.0, DOUBLE))));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(constant(6, BIGINT));
values.add(constant(7, BIGINT));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(constant(8, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), SET_CONTAINS);
}
use of io.trino.sql.relational.CallExpression in project trino by trinodb.
the class TestInCodeGenerator method testBigint.
@Test
public void testBigint() {
List<RowExpression> values = new ArrayList<>();
values.add(constant(Integer.MAX_VALUE + 1L, BIGINT));
values.add(constant(Integer.MIN_VALUE - 1L, BIGINT));
values.add(constant(3L, BIGINT));
assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
values.add(constant(null, BIGINT));
assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
values.add(new CallExpression(functionResolution.getCoercion(DOUBLE, BIGINT), Collections.singletonList(constant(12345678901234.0, DOUBLE))));
assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
values.add(constant(6L, BIGINT));
values.add(constant(7L, BIGINT));
assertEquals(checkSwitchGenerationCase(BIGINT, values), HASH_SWITCH);
values.add(constant(8L, BIGINT));
assertEquals(checkSwitchGenerationCase(BIGINT, values), SET_CONTAINS);
}
use of io.trino.sql.relational.CallExpression in project trino by trinodb.
the class TestExpressionOptimizer method testCastWithJsonParseOptimization.
private void testCastWithJsonParseOptimization(ResolvedFunction jsonParseFunction, Type targetType, String jsonStringToRowName) {
ResolvedFunction jsonCastFunction = functionResolution.getCoercion(JSON, targetType);
RowExpression jsonCastExpression = new CallExpression(jsonCastFunction, ImmutableList.of(call(jsonParseFunction, field(1, VARCHAR))));
RowExpression resultExpression = optimizer.optimize(jsonCastExpression);
assertEquals(resultExpression, call(functionResolution.getCoercion(QualifiedName.of(jsonStringToRowName), VARCHAR, targetType), field(1, VARCHAR)));
}
use of io.trino.sql.relational.CallExpression in project trino by trinodb.
the class TestPageProcessorCompiler method testNonDeterministicProject.
@Test
public void testNonDeterministicProject() {
ResolvedFunction lessThan = functionResolution.resolveOperator(LESS_THAN, ImmutableList.of(BIGINT, BIGINT));
CallExpression random = new CallExpression(functionResolution.resolveFunction(QualifiedName.of("random"), fromTypes(BIGINT)), singletonList(constant(10L, BIGINT)));
InputReferenceExpression col0 = field(0, BIGINT);
CallExpression lessThanRandomExpression = new CallExpression(lessThan, ImmutableList.of(col0, random));
PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(lessThanRandomExpression), MAX_BATCH_SIZE).get();
assertFalse(isDeterministic(lessThanRandomExpression));
Page page = new Page(createLongDictionaryBlock(1, 100));
Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock);
}
use of io.trino.sql.relational.CallExpression in project trino by trinodb.
the class TestPageProcessorCompiler method testNoCaching.
@Test
public void testNoCaching() {
ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();
ArrayType arrayType = new ArrayType(VARCHAR);
ResolvedFunction resolvedFunction = functionResolution.resolveFunction(QualifiedName.of("concat"), fromTypes(arrayType, arrayType));
projectionsBuilder.add(new CallExpression(resolvedFunction, ImmutableList.of(field(0, arrayType), field(1, arrayType))));
ImmutableList<RowExpression> projections = projectionsBuilder.build();
PageProcessor pageProcessor = compiler.compilePageProcessor(Optional.empty(), projections).get();
PageProcessor pageProcessor2 = compiler.compilePageProcessor(Optional.empty(), projections).get();
assertTrue(pageProcessor != pageProcessor2);
}
Aggregations