Search in sources :

Example 6 with OperatorFactory

use of io.trino.operator.OperatorFactory 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 7 with OperatorFactory

use of io.trino.operator.OperatorFactory in project trino by trinodb.

the class TestUnnestOperator method testUnnest.

@Test
public void testUnnest() {
    Type arrayType = new ArrayType(BIGINT);
    Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
    List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))).row(2L, arrayBlockOf(BIGINT, 99), null).row(3L, null, null).pageBreak().row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false, false);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT).row(1L, 2L, 4L, 5L).row(1L, 3L, null, null).row(2L, 99L, null, null).row(6L, 7L, 9L, 10L).row(6L, 8L, 11L, 12L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) OperatorFactory(io.trino.operator.OperatorFactory) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 8 with OperatorFactory

use of io.trino.operator.OperatorFactory in project trino by trinodb.

the class TestUnnestOperator method testOuterUnnestWithOrdinality.

@Test
public void testOuterUnnestWithOrdinality() {
    Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
    Type arrayType = new ArrayType(BIGINT);
    Type elementType = RowType.anonymous(ImmutableList.of(BIGINT, DOUBLE, VARCHAR));
    Type arrayOfRowType = new ArrayType(elementType);
    List<Page> input = rowPagesBuilder(BIGINT, mapType, arrayType, arrayOfRowType).row(1, mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(1, 2, 6, 7)), arrayBlockOf(BIGINT, 3), arrayBlockOf(elementType, ImmutableList.of(4, 5.5, "a"))).row(2, null, null, null).pageBreak().row(3, null, null, null).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2, 3), ImmutableList.of(mapType, arrayType, arrayOfRowType), true, true);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, DOUBLE, VARCHAR, BIGINT).row(1L, 1L, 2L, 3L, 4L, 5.5, "a", 1L).row(1L, 6L, 7L, null, null, null, null, 2L).row(2L, null, null, null, null, null, null, null).row(3L, null, null, null, null, null, null, null).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) OperatorFactory(io.trino.operator.OperatorFactory) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 9 with OperatorFactory

use of io.trino.operator.OperatorFactory in project trino by trinodb.

the class TestUnnestOperator method testUnnestWithOrdinality.

@Test
public void testUnnestWithOrdinality() {
    Type arrayType = new ArrayType(BIGINT);
    Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
    List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(BIGINT, 2, 3), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(4, 5))).row(2L, arrayBlockOf(BIGINT, 99), null).row(3L, null, null).pageBreak().row(6L, arrayBlockOf(BIGINT, 7, 8), mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(9, 10, 11, 12))).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), true, false);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT).row(1L, 2L, 4L, 5L, 1L).row(1L, 3L, null, null, 2L).row(2L, 99L, null, null, 1L).row(6L, 7L, 9L, 10L, 1L).row(6L, 8L, 11L, 12L, 2L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) OperatorFactory(io.trino.operator.OperatorFactory) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 10 with OperatorFactory

use of io.trino.operator.OperatorFactory in project trino by trinodb.

the class TestUnnestOperator method testUnnestNonNumericDoubles.

@Test
public void testUnnestNonNumericDoubles() {
    Type arrayType = new ArrayType(DOUBLE);
    Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
    List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(DOUBLE, NEGATIVE_INFINITY, POSITIVE_INFINITY, NaN), mapBlockOf(BIGINT, DOUBLE, ImmutableMap.of(1, NEGATIVE_INFINITY, 2, POSITIVE_INFINITY, 3, NaN))).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false, false);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE, BIGINT, DOUBLE).row(1L, NEGATIVE_INFINITY, 1L, NEGATIVE_INFINITY).row(1L, POSITIVE_INFINITY, 2L, POSITIVE_INFINITY).row(1L, NaN, 3L, NaN).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) OperatorFactory(io.trino.operator.OperatorFactory) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

OperatorFactory (io.trino.operator.OperatorFactory)54 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)38 Test (org.testng.annotations.Test)35 MaterializedResult (io.trino.testing.MaterializedResult)34 Type (io.trino.spi.type.Type)33 Page (io.trino.spi.Page)31 RowPagesBuilder (io.trino.RowPagesBuilder)29 TaskContext (io.trino.operator.TaskContext)29 TestingTaskContext (io.trino.testing.TestingTaskContext)29 ValuesOperatorFactory (io.trino.operator.ValuesOperator.ValuesOperatorFactory)26 PageBufferOperatorFactory (io.trino.operator.index.PageBufferOperator.PageBufferOperatorFactory)26 WorkProcessorOperatorFactory (io.trino.operator.WorkProcessorOperatorFactory)25 JoinTestUtils.innerJoinOperatorFactory (io.trino.operator.join.JoinTestUtils.innerJoinOperatorFactory)25 BuildSideSetup (io.trino.operator.join.JoinTestUtils.BuildSideSetup)23 DriverContext (io.trino.operator.DriverContext)17 Operator (io.trino.operator.Operator)13 ImmutableList (com.google.common.collect.ImmutableList)11 Driver (io.trino.operator.Driver)11 WorkProcessorOperator (io.trino.operator.WorkProcessorOperator)11 ArrayList (java.util.ArrayList)10