Search in sources :

Example 6 with PagesSpatialIndexFactory

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

the class TestSpatialJoinOperator method testDistributedSpatialSelfJoin.

@Test
public void testDistributedSpatialSelfJoin() {
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, true).addDriverContext();
    RowPagesBuilder pages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER)).row(POLYGON_A, "A", 1).row(POLYGON_A, "A", 2).row(null, "null", null).pageBreak().row(POLYGON_B, "B", 0).row(POLYGON_B, "B", 2);
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("A", "A").row("A", "B").row("B", "A").row("B", "B").build();
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.intersects(probe), Optional.empty(), Optional.of(2), Optional.of(KDB_TREE_JSON), Optional.empty(), pages);
    OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, pages.getTypes(), Ints.asList(1), 0, Optional.of(2), pagesSpatialIndexFactory);
    assertOperatorEquals(joinOperatorFactory, driverContext, pages.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) MaterializedResult(io.trino.testing.MaterializedResult) PagesSpatialIndexFactory(io.trino.operator.PagesSpatialIndexFactory) Test(org.testng.annotations.Test)

Example 7 with PagesSpatialIndexFactory

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

the class TestSpatialJoinOperator method buildIndex.

private PagesSpatialIndexFactory buildIndex(DriverContext driverContext, SpatialPredicate spatialRelationshipTest, Optional<Integer> radiusChannel, Optional<Integer> partitionChannel, Optional<String> kdbTreeJson, Optional<InternalJoinFilterFunction> filterFunction, RowPagesBuilder buildPages) {
    Optional<JoinFilterFunctionCompiler.JoinFilterFunctionFactory> filterFunctionFactory = filterFunction.map(function -> (session, addresses, pages) -> new StandardJoinFilterFunction(function, addresses, pages));
    ValuesOperator.ValuesOperatorFactory valuesOperatorFactory = new ValuesOperator.ValuesOperatorFactory(0, new PlanNodeId("test"), buildPages.build());
    SpatialIndexBuilderOperatorFactory buildOperatorFactory = new SpatialIndexBuilderOperatorFactory(1, new PlanNodeId("test"), buildPages.getTypes(), Ints.asList(1), 0, radiusChannel, partitionChannel, spatialRelationshipTest, kdbTreeJson, filterFunctionFactory, 10_000, new TestingFactory(false));
    Driver driver = Driver.createDriver(driverContext, valuesOperatorFactory.createOperator(driverContext), buildOperatorFactory.createOperator(driverContext));
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildOperatorFactory.getPagesSpatialIndexFactory();
    ListenableFuture<PagesSpatialIndex> pagesSpatialIndex = pagesSpatialIndexFactory.createPagesSpatialIndex();
    while (!pagesSpatialIndex.isDone()) {
        driver.process();
    }
    runDriverInThread(executor, driver);
    return pagesSpatialIndexFactory;
}
Also used : SpatialIndexBuilderOperatorFactory(io.trino.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) StandardJoinFilterFunction(io.trino.operator.join.StandardJoinFilterFunction) PagesSpatialIndex(io.trino.operator.PagesSpatialIndex) Driver(io.trino.operator.Driver) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TestingFactory(io.trino.operator.PagesIndex.TestingFactory) ValuesOperator(io.trino.operator.ValuesOperator) PagesSpatialIndexFactory(io.trino.operator.PagesSpatialIndexFactory)

Aggregations

PagesSpatialIndexFactory (io.trino.operator.PagesSpatialIndexFactory)7 SpatialIndexBuilderOperatorFactory (io.trino.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory)7 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)7 DriverContext (io.trino.operator.DriverContext)6 OperatorFactory (io.trino.operator.OperatorFactory)6 SpatialJoinOperatorFactory (io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory)6 RowPagesBuilder (io.trino.RowPagesBuilder)5 TaskContext (io.trino.operator.TaskContext)5 MaterializedResult (io.trino.testing.MaterializedResult)5 TestingTaskContext (io.trino.testing.TestingTaskContext)5 Test (org.testng.annotations.Test)5 ValuesOperator (io.trino.operator.ValuesOperator)3 Driver (io.trino.operator.Driver)2 Operator (io.trino.operator.Operator)2 TestingFactory (io.trino.operator.PagesIndex.TestingFactory)2 PagesSpatialIndex (io.trino.operator.PagesSpatialIndex)2 PipelineContext (io.trino.operator.PipelineContext)2 StandardJoinFilterFunction (io.trino.operator.join.StandardJoinFilterFunction)2 GeoFunctions.stPoint (io.trino.plugin.geospatial.GeoFunctions.stPoint)2 ImmutableList (com.google.common.collect.ImmutableList)1