Search in sources :

Example 6 with CallExpression

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);
}
Also used : ArrayList(java.util.ArrayList) RowExpression(io.trino.sql.relational.RowExpression) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 7 with CallExpression

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);
}
Also used : ArrayList(java.util.ArrayList) RowExpression(io.trino.sql.relational.RowExpression) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 8 with CallExpression

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)));
}
Also used : ResolvedFunction(io.trino.metadata.ResolvedFunction) RowExpression(io.trino.sql.relational.RowExpression) CallExpression(io.trino.sql.relational.CallExpression)

Example 9 with CallExpression

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);
}
Also used : InputReferenceExpression(io.trino.sql.relational.InputReferenceExpression) PageProcessor(io.trino.operator.project.PageProcessor) ResolvedFunction(io.trino.metadata.ResolvedFunction) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(io.trino.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(io.trino.operator.DriverYieldSignal) Page(io.trino.spi.Page) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 10 with CallExpression

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);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) PageProcessor(io.trino.operator.project.PageProcessor) ImmutableList(com.google.common.collect.ImmutableList) ResolvedFunction(io.trino.metadata.ResolvedFunction) RowExpression(io.trino.sql.relational.RowExpression) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Aggregations

CallExpression (io.trino.sql.relational.CallExpression)13 Test (org.testng.annotations.Test)10 RowExpression (io.trino.sql.relational.RowExpression)7 ResolvedFunction (io.trino.metadata.ResolvedFunction)6 DriverYieldSignal (io.trino.operator.DriverYieldSignal)4 PageProcessor (io.trino.operator.project.PageProcessor)4 Page (io.trino.spi.Page)4 ConstantExpression (io.trino.sql.relational.ConstantExpression)3 InputReferenceExpression (io.trino.sql.relational.InputReferenceExpression)3 Scope (io.airlift.bytecode.Scope)2 BlockAssertions.createLongDictionaryBlock (io.trino.block.BlockAssertions.createLongDictionaryBlock)2 DictionaryBlock (io.trino.spi.block.DictionaryBlock)2 ArrayType (io.trino.spi.type.ArrayType)2 LambdaDefinitionExpression (io.trino.sql.relational.LambdaDefinitionExpression)2 RowExpressionVisitor (io.trino.sql.relational.RowExpressionVisitor)2 SpecialForm (io.trino.sql.relational.SpecialForm)2 VariableReferenceExpression (io.trino.sql.relational.VariableReferenceExpression)2 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)1