Search in sources :

Example 6 with RowExpression

use of io.trino.sql.relational.RowExpression in project trino by trinodb.

the class TestFilterAndProjectOperator method testMergeOutput.

@Test
public void testMergeOutput() {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).build();
    TestingFunctionResolution functionResolution = new TestingFunctionResolution();
    RowExpression filter = call(functionResolution.resolveOperator(EQUAL, ImmutableList.of(BIGINT, BIGINT)), field(1, BIGINT), constant(10L, BIGINT));
    ExpressionCompiler compiler = functionResolution.getExpressionCompiler();
    Supplier<PageProcessor> processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(1, BIGINT)));
    OperatorFactory operatorFactory = FilterAndProjectOperator.createOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(BIGINT), DataSize.of(64, KILOBYTE), 2);
    List<Page> expected = rowPagesBuilder(BIGINT).row(10L).row(10L).row(10L).row(10L).build();
    assertOperatorEquals(operatorFactory, ImmutableList.of(BIGINT), driverContext, input, expected);
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PageProcessor(io.trino.operator.project.PageProcessor) RowExpression(io.trino.sql.relational.RowExpression) Page(io.trino.spi.Page) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) Test(org.testng.annotations.Test)

Example 7 with RowExpression

use of io.trino.sql.relational.RowExpression in project trino by trinodb.

the class FunctionAssertions method executeFilterWithAll.

private List<Boolean> executeFilterWithAll(String filter, Session session, boolean executeWithNoInputColumns, ExpressionCompiler compiler) {
    requireNonNull(filter, "filter is null");
    Expression filterExpression = createExpression(session, filter, getPlannerContext(), INPUT_TYPES);
    RowExpression filterRowExpression = toRowExpression(session, filterExpression);
    List<Boolean> results = new ArrayList<>();
    // execute as standalone operator
    OperatorFactory operatorFactory = compileFilterProject(Optional.of(filterRowExpression), constant(true, BOOLEAN), compiler);
    results.add(executeFilter(operatorFactory, session));
    if (executeWithNoInputColumns) {
        // execute as standalone operator
        operatorFactory = compileFilterWithNoInputColumns(filterRowExpression, compiler);
        results.add(executeFilterWithNoInputColumns(operatorFactory, session));
    }
    // interpret
    Boolean interpretedValue = (Boolean) interpret(filterExpression, BOOLEAN, session);
    if (interpretedValue == null) {
        interpretedValue = false;
    }
    results.add(interpretedValue);
    // execute over normal operator
    SourceOperatorFactory scanProjectOperatorFactory = compileScanFilterProject(Optional.of(filterRowExpression), constant(true, BOOLEAN), compiler);
    boolean scanOperatorValue = executeFilter(scanProjectOperatorFactory, createNormalSplit(), session);
    results.add(scanOperatorValue);
    // execute over record set
    boolean recordValue = executeFilter(scanProjectOperatorFactory, createRecordSetSplit(), session);
    results.add(recordValue);
    // If the filter does not need bound values, execute query using full engine
    if (!needsBoundValue(filterExpression)) {
        MaterializedResult result = runner.execute("SELECT TRUE WHERE " + filter);
        assertEquals(result.getTypes().size(), 1);
        Boolean queryResult;
        if (result.getMaterializedRows().isEmpty()) {
            queryResult = false;
        } else {
            assertEquals(result.getMaterializedRows().size(), 1);
            queryResult = (Boolean) Iterables.getOnlyElement(result.getMaterializedRows()).getField(0);
        }
        results.add(queryResult);
    }
    return results;
}
Also used : ExpressionTestUtils.createExpression(io.trino.sql.ExpressionTestUtils.createExpression) Expression(io.trino.sql.tree.Expression) RowExpression(io.trino.sql.relational.RowExpression) SourceOperatorFactory(io.trino.operator.SourceOperatorFactory) OperatorFactory(io.trino.operator.OperatorFactory) ArrayList(java.util.ArrayList) RowExpression(io.trino.sql.relational.RowExpression) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MaterializedResult(io.trino.testing.MaterializedResult) SourceOperatorFactory(io.trino.operator.SourceOperatorFactory)

Example 8 with RowExpression

use of io.trino.sql.relational.RowExpression in project trino by trinodb.

the class BenchmarkPageProcessor method setup.

@Setup
public void setup() {
    inputPage = createInputPage();
    TestingFunctionResolution functionResolution = new TestingFunctionResolution();
    RowExpression filterExpression = createFilterExpression(functionResolution);
    RowExpression projectExpression = createProjectExpression(functionResolution);
    ExpressionCompiler expressionCompiler = functionResolution.getExpressionCompiler();
    compiledProcessor = expressionCompiler.compilePageProcessor(Optional.of(filterExpression), ImmutableList.of(projectExpression)).get();
}
Also used : TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) RowExpression(io.trino.sql.relational.RowExpression) Setup(org.openjdk.jmh.annotations.Setup)

Example 9 with RowExpression

use of io.trino.sql.relational.RowExpression 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 10 with RowExpression

use of io.trino.sql.relational.RowExpression 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)

Aggregations

RowExpression (io.trino.sql.relational.RowExpression)34 Test (org.testng.annotations.Test)14 PageProcessor (io.trino.operator.project.PageProcessor)13 Page (io.trino.spi.Page)9 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)9 CursorProcessor (io.trino.operator.project.CursorProcessor)7 CallExpression (io.trino.sql.relational.CallExpression)7 MaterializedResult (io.trino.testing.MaterializedResult)7 ImmutableList (com.google.common.collect.ImmutableList)6 BytecodeBlock (io.airlift.bytecode.BytecodeBlock)6 Variable (io.airlift.bytecode.Variable)6 CatalogName (io.trino.connector.CatalogName)6 Split (io.trino.metadata.Split)6 ExpressionCompiler (io.trino.sql.gen.ExpressionCompiler)6 TestingSplit (io.trino.testing.TestingSplit)6 IfStatement (io.airlift.bytecode.control.IfStatement)5 Type (io.trino.spi.type.Type)5 Expression (io.trino.sql.tree.Expression)5 LabelNode (io.airlift.bytecode.instruction.LabelNode)4 FunctionManager (io.trino.metadata.FunctionManager)4