Search in sources :

Example 1 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class TestSpatialJoinOperator method testEmptyBuild.

@Test
public void testEmptyBuild() {
    TaskContext taskContext = createTaskContext();
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR));
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(POINT_X, "x").row(null, "null").row(POINT_Y, "y").pageBreak().row(POINT_Z, "z").pageBreak().row(POINT_W, "w");
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).build();
    assertSpatialJoin(taskContext, INNER, buildPages, probePages, expected);
}
Also used : TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 2 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class TestSpatialJoinOperator method testDuplicateProbeFactory.

@Test(dataProvider = "testDuplicateProbeFactoryDataProvider")
public void testDuplicateProbeFactory(boolean createSecondaryOperators) throws Exception {
    TaskContext taskContext = createTaskContext();
    PipelineContext pipelineContext = taskContext.addPipelineContext(0, true, true, false);
    DriverContext probeDriver = pipelineContext.addDriverContext();
    DriverContext buildDriver = pipelineContext.addDriverContext();
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, DOUBLE)).row(stPoint(0, 0), "0_0", 1.5);
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(buildDriver, (build, probe, r) -> build.distance(probe) <= r.getAsDouble(), Optional.of(2), Optional.empty(), buildPages);
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(stPoint(0, 1), "0_1");
    OperatorFactory firstFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, probePages.getTypes(), Ints.asList(1), 0, Optional.empty(), pagesSpatialIndexFactory);
    for (int i = 0; i < 3; i++) {
        DriverContext secondDriver = pipelineContext.addDriverContext();
        OperatorFactory secondFactory = firstFactory.duplicate();
        if (createSecondaryOperators) {
            try (Operator secondOperator = secondFactory.createOperator(secondDriver)) {
                assertEquals(toPages(secondOperator, emptyIterator()), ImmutableList.of());
            }
        }
        secondFactory.noMoreOperators();
    }
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("0_1", "0_0").build();
    assertOperatorEquals(firstFactory, probeDriver, probePages.build(), expected);
}
Also used : SpatialJoinOperatorFactory(io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Operator(io.trino.operator.Operator) ValuesOperator(io.trino.operator.ValuesOperator) DriverContext(io.trino.operator.DriverContext) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) PipelineContext(io.trino.operator.PipelineContext) OperatorFactory(io.trino.operator.OperatorFactory) SpatialIndexBuilderOperatorFactory(io.trino.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) SpatialJoinOperatorFactory(io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PagesSpatialIndexFactory(io.trino.operator.PagesSpatialIndexFactory) MaterializedResult(io.trino.testing.MaterializedResult) GeoFunctions.stPoint(io.trino.plugin.geospatial.GeoFunctions.stPoint) Test(org.testng.annotations.Test)

Example 3 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class TestSpatialJoinOperator method testDistanceQuery.

@Test
public void testDistanceQuery() {
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, DOUBLE)).row(stPoint(0, 0), "0_0", 1.5).row(null, "null", 1.5).row(stPoint(1, 0), "1_0", 1.5).pageBreak().row(stPoint(3, 0), "3_0", 1.5).pageBreak().row(stPoint(10, 0), "10_0", 1.5);
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.distance(probe) <= r.getAsDouble(), Optional.of(2), Optional.empty(), buildPages);
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(stPoint(0, 1), "0_1").row(null, "null").row(stPoint(1, 1), "1_1").pageBreak().row(stPoint(3, 1), "3_1").pageBreak().row(stPoint(10, 1), "10_1");
    OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, probePages.getTypes(), Ints.asList(1), 0, Optional.empty(), pagesSpatialIndexFactory);
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("0_1", "0_0").row("0_1", "1_0").row("1_1", "0_0").row("1_1", "1_0").row("3_1", "3_0").row("10_1", "10_0").build();
    assertOperatorEquals(joinOperatorFactory, driverContext, probePages.build(), expected);
}
Also used : SpatialJoinOperatorFactory(io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) DriverContext(io.trino.operator.DriverContext) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) OperatorFactory(io.trino.operator.OperatorFactory) SpatialIndexBuilderOperatorFactory(io.trino.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) SpatialJoinOperatorFactory(io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PagesSpatialIndexFactory(io.trino.operator.PagesSpatialIndexFactory) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 4 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class TestSpatialJoinOperator method testEmptyBuildLeftJoin.

@Test
public void testEmptyBuildLeftJoin() {
    TaskContext taskContext = createTaskContext();
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR));
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(POINT_X, "x").row(null, "null").row(POINT_Y, "y").pageBreak().row(POINT_Z, "z").pageBreak().row(POINT_W, "w");
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("x", null).row("null", null).row("y", null).row("z", null).row("w", null).build();
    assertSpatialJoin(taskContext, LEFT, buildPages, probePages, expected);
}
Also used : TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 5 with MaterializedResult

use of io.trino.testing.MaterializedResult in project trino by trinodb.

the class TestSpatialJoinOperator method testSpatialLeftJoin.

@Test
public void testSpatialLeftJoin() {
    TaskContext taskContext = createTaskContext();
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(POLYGON_A, "A").row(null, "null").pageBreak().row(POLYGON_B, "B");
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(POINT_X, "x").row(null, "null").row(POINT_Y, "y").pageBreak().row(POINT_Z, "z").pageBreak().row(POINT_W, "w");
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("x", "A").row("null", null).row("y", "A").row("y", "B").row("z", "B").row("w", null).build();
    assertSpatialJoin(taskContext, LEFT, buildPages, probePages, expected);
}
Also used : TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

MaterializedResult (io.trino.testing.MaterializedResult)328 Test (org.testng.annotations.Test)248 Page (io.trino.spi.Page)103 BaseConnectorTest (io.trino.testing.BaseConnectorTest)64 MaterializedRow (io.trino.testing.MaterializedRow)63 Type (io.trino.spi.type.Type)61 RowPagesBuilder (io.trino.RowPagesBuilder)57 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)51 OperatorAssertion.toMaterializedResult (io.trino.operator.OperatorAssertion.toMaterializedResult)41 TaskContext (io.trino.operator.TaskContext)37 TestingTaskContext (io.trino.testing.TestingTaskContext)37 OperatorFactory (io.trino.operator.OperatorFactory)31 Language (org.intellij.lang.annotations.Language)31 ConnectorSession (io.trino.spi.connector.ConnectorSession)27 Session (io.trino.Session)24 ColumnHandle (io.trino.spi.connector.ColumnHandle)24 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)24 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)23 ImmutableList (com.google.common.collect.ImmutableList)22 Constraint (io.trino.spi.connector.Constraint)20