Search in sources :

Example 6 with PagesSpatialIndexFactory

use of com.facebook.presto.operator.PagesSpatialIndexFactory in project presto by prestodb.

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);
    // Make sure that spatial index reference counting works with duplicate factories
    joinOperatorFactory.duplicate().noMoreOperators();
    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();
    assertOperatorEqualsIgnoreOrder(joinOperatorFactory, driverContext, probePages.build(), expected);
}
Also used : SpatialJoinOperatorFactory(com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) DriverContext(com.facebook.presto.operator.DriverContext) TestingTaskContext(com.facebook.presto.testing.TestingTaskContext) TaskContext(com.facebook.presto.operator.TaskContext) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) SpatialJoinOperatorFactory(com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) OperatorFactory(com.facebook.presto.operator.OperatorFactory) SpatialIndexBuilderOperatorFactory(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) PagesSpatialIndexFactory(com.facebook.presto.operator.PagesSpatialIndexFactory) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

PagesSpatialIndexFactory (com.facebook.presto.operator.PagesSpatialIndexFactory)6 SpatialIndexBuilderOperatorFactory (com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory)6 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)6 DriverContext (com.facebook.presto.operator.DriverContext)5 OperatorFactory (com.facebook.presto.operator.OperatorFactory)5 SpatialJoinOperatorFactory (com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory)5 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)4 TaskContext (com.facebook.presto.operator.TaskContext)4 MaterializedResult (com.facebook.presto.testing.MaterializedResult)4 TestingTaskContext (com.facebook.presto.testing.TestingTaskContext)4 Test (org.testng.annotations.Test)4 Driver (com.facebook.presto.operator.Driver)2 TestingFactory (com.facebook.presto.operator.PagesIndex.TestingFactory)2 PagesSpatialIndex (com.facebook.presto.operator.PagesSpatialIndex)2 StandardJoinFilterFunction (com.facebook.presto.operator.StandardJoinFilterFunction)2 ValuesOperator (com.facebook.presto.operator.ValuesOperator)2 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 RowPagesBuilder.rowPagesBuilder (com.facebook.presto.RowPagesBuilder.rowPagesBuilder)1 TEST_SESSION (com.facebook.presto.SessionTestUtils.TEST_SESSION)1 Page (com.facebook.presto.common.Page)1