Search in sources :

Example 6 with TaskContext

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

the class QueryContext method addTaskContext.

public TaskContext addTaskContext(TaskStateMachine taskStateMachine, Session session, Optional<PlanNode> taskPlan, boolean perOperatorCpuTimerEnabled, boolean cpuTimerEnabled, boolean perOperatorAllocationTrackingEnabled, boolean allocationTrackingEnabled, boolean legacyLifespanCompletionCondition) {
    TaskContext taskContext = TaskContext.createTaskContext(this, taskStateMachine, gcMonitor, notificationExecutor, yieldExecutor, session, queryMemoryContext.newMemoryTrackingContext(), taskPlan, perOperatorCpuTimerEnabled, cpuTimerEnabled, perOperatorAllocationTrackingEnabled, allocationTrackingEnabled, legacyLifespanCompletionCondition);
    taskContexts.put(taskStateMachine.getTaskId(), taskContext);
    return taskContext;
}
Also used : TaskContext(com.facebook.presto.operator.TaskContext)

Example 7 with TaskContext

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

the class MemoryLocalQueryRunner method execute.

public List<Page> execute(@Language("SQL") String query) {
    MemoryPool memoryPool = new MemoryPool(new MemoryPoolId("test"), new DataSize(2, GIGABYTE));
    SpillSpaceTracker spillSpaceTracker = new SpillSpaceTracker(new DataSize(1, GIGABYTE));
    QueryContext queryContext = new QueryContext(new QueryId("test"), new DataSize(1, GIGABYTE), new DataSize(2, GIGABYTE), new DataSize(1, GIGABYTE), new DataSize(2, GIGABYTE), memoryPool, new TestingGcMonitor(), localQueryRunner.getExecutor(), localQueryRunner.getScheduler(), new DataSize(4, GIGABYTE), spillSpaceTracker, listJsonCodec(TaskMemoryReservationSummary.class));
    TaskContext taskContext = queryContext.addTaskContext(new TaskStateMachine(new TaskId("query", 0, 0, 0), localQueryRunner.getExecutor()), localQueryRunner.getDefaultSession(), Optional.empty(), false, false, false, false, false);
    // Use NullOutputFactory to avoid coping out results to avoid affecting benchmark results
    ImmutableList.Builder<Page> output = ImmutableList.builder();
    List<Driver> drivers = localQueryRunner.createDrivers(query, new PageConsumerOperator.PageConsumerOutputFactory(types -> output::add), taskContext);
    boolean done = false;
    while (!done) {
        boolean processed = false;
        for (Driver driver : drivers) {
            if (!driver.isFinished()) {
                driver.process();
                processed = true;
            }
        }
        done = !processed;
    }
    return output.build();
}
Also used : TaskMemoryReservationSummary(com.facebook.presto.operator.TaskMemoryReservationSummary) Page(com.facebook.presto.common.Page) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) JsonCodec.listJsonCodec(com.facebook.airlift.json.JsonCodec.listJsonCodec) MemoryConnectorFactory(com.facebook.presto.plugin.memory.MemoryConnectorFactory) SpillSpaceTracker(com.facebook.presto.spiller.SpillSpaceTracker) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) QueryContext(com.facebook.presto.memory.QueryContext) TableHandle(com.facebook.presto.spi.TableHandle) MemoryPool(com.facebook.presto.memory.MemoryPool) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) TaskContext(com.facebook.presto.operator.TaskContext) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) TestingGcMonitor(com.facebook.airlift.stats.TestingGcMonitor) Driver(com.facebook.presto.operator.Driver) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) Plugin(com.facebook.presto.spi.Plugin) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) DataSize(io.airlift.units.DataSize) List(java.util.List) TaskId(com.facebook.presto.execution.TaskId) QueryId(com.facebook.presto.spi.QueryId) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) TaskMemoryReservationSummary(com.facebook.presto.operator.TaskMemoryReservationSummary) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) Metadata(com.facebook.presto.metadata.Metadata) SpillSpaceTracker(com.facebook.presto.spiller.SpillSpaceTracker) TaskContext(com.facebook.presto.operator.TaskContext) TaskId(com.facebook.presto.execution.TaskId) ImmutableList(com.google.common.collect.ImmutableList) QueryId(com.facebook.presto.spi.QueryId) Driver(com.facebook.presto.operator.Driver) Page(com.facebook.presto.common.Page) QueryContext(com.facebook.presto.memory.QueryContext) TaskStateMachine(com.facebook.presto.execution.TaskStateMachine) PageConsumerOperator(com.facebook.presto.testing.PageConsumerOperator) DataSize(io.airlift.units.DataSize) TestingGcMonitor(com.facebook.airlift.stats.TestingGcMonitor) MemoryPoolId(com.facebook.presto.spi.memory.MemoryPoolId) MemoryPool(com.facebook.presto.memory.MemoryPool)

Example 8 with TaskContext

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

the class TestSpatialJoinOperator method testDistributedSpatialJoin.

@Test
public void testDistributedSpatialJoin() {
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, true).addDriverContext();
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER));
    addGeometryPartitionRows(buildPages, POLYGON_A, "A");
    buildPages.row(null, "null", null);
    buildPages.pageBreak();
    addGeometryPartitionRows(buildPages, POLYGON_B, "B");
    addGeometryPartitionRows(buildPages, POLYGON_C, "C");
    addGeometryPartitionRows(buildPages, POLYGON_D, "D");
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER));
    addGeometryPartitionRows(probePages, POINT_X, "x");
    probePages.row(null, "null", null);
    addGeometryPartitionRows(probePages, POINT_Y, "y");
    probePages.pageBreak();
    addGeometryPartitionRows(probePages, POINT_Z, "z");
    addGeometryPartitionRows(probePages, POINT_W, "w");
    addGeometryPartitionRows(probePages, POINT_V, "v");
    addGeometryPartitionRows(probePages, MULTIPOINT_U, "u");
    probePages.pageBreak();
    addGeometryPartitionRows(probePages, MULTIPOINT_T, "t");
    addGeometryPartitionRows(probePages, POINT_S, "s");
    addGeometryPartitionRows(probePages, MULTIPOINT_R, "r");
    addGeometryPartitionRows(probePages, POINT_Q, "q");
    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR)).row("x", "A").row("y", "A").row("y", "B").row("z", "B").row("v", "C").row("u", "C").row("t", "C").row("s", "D").row("r", "C").row("r", "D").build();
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.intersects(probe), Optional.empty(), Optional.of(2), Optional.of(KDB_TREE_JSON), Optional.empty(), buildPages);
    OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, probePages.getTypes(), Ints.asList(1), 0, Optional.of(2), pagesSpatialIndexFactory);
    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) MaterializedResult(com.facebook.presto.testing.MaterializedResult) PagesSpatialIndexFactory(com.facebook.presto.operator.PagesSpatialIndexFactory) Test(org.testng.annotations.Test)

Example 9 with TaskContext

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

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));
    addGeometryPartitionRows(pages, POLYGON_A, "A");
    pages.row(null, "null", null);
    pages.pageBreak();
    addGeometryPartitionRows(pages, POLYGON_B, "B");
    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);
    assertOperatorEqualsIgnoreOrder(joinOperatorFactory, driverContext, pages.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) MaterializedResult(com.facebook.presto.testing.MaterializedResult) PagesSpatialIndexFactory(com.facebook.presto.operator.PagesSpatialIndexFactory) Test(org.testng.annotations.Test)

Example 10 with TaskContext

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

the class TestSpatialJoinOperator method testYield.

@Test
public void testYield() {
    // create a filter function that yields for every probe match
    // verify we will yield #match times totally
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    // force a yield for every match
    AtomicInteger filterFunctionCalls = new AtomicInteger();
    InternalJoinFilterFunction filterFunction = new TestInternalJoinFilterFunction(((leftPosition, leftPage, rightPosition, rightPage) -> {
        filterFunctionCalls.incrementAndGet();
        driverContext.getYieldSignal().forceYieldForTesting();
        return true;
    }));
    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR)).row(POLYGON_A, "A").pageBreak().row(POLYGON_B, "B");
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.contains(probe), Optional.empty(), Optional.of(filterFunction), buildPages);
    // 10 points in polygon A (x0...x9)
    // 10 points in polygons A and B (y0...y9)
    // 10 points in polygon B (z0...z9)
    // 40 total matches
    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR));
    for (int i = 0; i < 10; i++) {
        probePages.row(stPoint(1 + 0.1 * i, 1 + 0.1 * i), "x" + i);
    }
    for (int i = 0; i < 10; i++) {
        probePages.row(stPoint(4.5 + 0.01 * i, 4.5 + 0.01 * i), "y" + i);
    }
    for (int i = 0; i < 10; i++) {
        probePages.row(stPoint(6 + 0.1 * i, 6 + 0.1 * i), "z" + i);
    }
    List<Page> probeInput = probePages.build();
    OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, probePages.getTypes(), Ints.asList(1), 0, Optional.empty(), pagesSpatialIndexFactory);
    Operator operator = joinOperatorFactory.createOperator(driverContext);
    assertTrue(operator.needsInput());
    operator.addInput(probeInput.get(0));
    operator.finish();
    // we will yield 40 times due to filterFunction
    for (int i = 0; i < 40; i++) {
        driverContext.getYieldSignal().setWithDelay(5 * SECONDS.toNanos(1), driverContext.getYieldExecutor());
        assertNull(operator.getOutput());
        assertEquals(filterFunctionCalls.get(), i + 1, "Expected join to stop processing (yield) after calling filter function once");
        driverContext.getYieldSignal().reset();
    }
    // delayed yield is not going to prevent operator from producing a page now (yield won't be forced because filter function won't be called anymore)
    driverContext.getYieldSignal().setWithDelay(5 * SECONDS.toNanos(1), driverContext.getYieldExecutor());
    Page output = operator.getOutput();
    assertNotNull(output);
    // make sure we have 40 matches
    assertEquals(output.getPositionCount(), 40);
}
Also used : Page(com.facebook.presto.common.Page) TestingFactory(com.facebook.presto.operator.PagesIndex.TestingFactory) MaterializedResult.resultBuilder(com.facebook.presto.testing.MaterializedResult.resultBuilder) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) GeoFunctions.spatialPartitions(com.facebook.presto.plugin.geospatial.GeoFunctions.spatialPartitions) Type(com.facebook.presto.sql.planner.plan.SpatialJoinNode.Type) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) SpatialJoinOperatorFactory(com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) GeoFunctions.stGeometryFromText(com.facebook.presto.plugin.geospatial.GeoFunctions.stGeometryFromText) Slices(io.airlift.slice.Slices) StandardJoinFilterFunction(com.facebook.presto.operator.StandardJoinFilterFunction) Operator(com.facebook.presto.operator.Operator) SynchronousQueue(java.util.concurrent.SynchronousQueue) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) BeforeMethod(org.testng.annotations.BeforeMethod) LEFT(com.facebook.presto.sql.planner.plan.SpatialJoinNode.Type.LEFT) Assert.assertNotNull(org.testng.Assert.assertNotNull) Rectangle(com.facebook.presto.geospatial.Rectangle) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) OperatorAssertion.assertOperatorEqualsIgnoreOrder(com.facebook.presto.operator.OperatorAssertion.assertOperatorEqualsIgnoreOrder) PagesSpatialIndex(com.facebook.presto.operator.PagesSpatialIndex) List(java.util.List) KdbTreeUtils(com.facebook.presto.geospatial.KdbTreeUtils) InternalJoinFilterFunction(com.facebook.presto.operator.InternalJoinFilterFunction) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) Optional(java.util.Optional) SpatialPredicate(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialPredicate) RowPagesBuilder.rowPagesBuilder(com.facebook.presto.RowPagesBuilder.rowPagesBuilder) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) Assert.assertEquals(org.testng.Assert.assertEquals) ValuesOperator(com.facebook.presto.operator.ValuesOperator) PrestoException(com.facebook.presto.spi.PrestoException) OperatorFactory(com.facebook.presto.operator.OperatorFactory) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) PagesSpatialIndexFactory(com.facebook.presto.operator.PagesSpatialIndexFactory) SpatialIndexBuilderOperatorFactory(com.facebook.presto.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) KdbTree(com.facebook.presto.geospatial.KdbTree) TestingTaskContext(com.facebook.presto.testing.TestingTaskContext) ExecutorService(java.util.concurrent.ExecutorService) GEOMETRY(com.facebook.presto.plugin.geospatial.GeometryType.GEOMETRY) TaskContext(com.facebook.presto.operator.TaskContext) GeoFunctions.stPoint(com.facebook.presto.plugin.geospatial.GeoFunctions.stPoint) JoinFilterFunctionCompiler(com.facebook.presto.sql.gen.JoinFilterFunctionCompiler) Driver(com.facebook.presto.operator.Driver) Ints(com.google.common.primitives.Ints) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Assert.assertTrue(org.testng.Assert.assertTrue) DriverContext(com.facebook.presto.operator.DriverContext) Block(com.facebook.presto.common.block.Block) INNER(com.facebook.presto.sql.planner.plan.SpatialJoinNode.Type.INNER) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Operator(com.facebook.presto.operator.Operator) ValuesOperator(com.facebook.presto.operator.ValuesOperator) DriverContext(com.facebook.presto.operator.DriverContext) TestingTaskContext(com.facebook.presto.testing.TestingTaskContext) TaskContext(com.facebook.presto.operator.TaskContext) RowPagesBuilder(com.facebook.presto.RowPagesBuilder) Page(com.facebook.presto.common.Page) InternalJoinFilterFunction(com.facebook.presto.operator.InternalJoinFilterFunction) GeoFunctions.stPoint(com.facebook.presto.plugin.geospatial.GeoFunctions.stPoint) SpatialJoinOperatorFactory(com.facebook.presto.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Test(org.testng.annotations.Test)

Aggregations

TaskContext (com.facebook.presto.operator.TaskContext)35 Test (org.testng.annotations.Test)15 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)13 DriverContext (com.facebook.presto.operator.DriverContext)10 OperatorContext (com.facebook.presto.operator.OperatorContext)10 TestingTaskContext (com.facebook.presto.testing.TestingTaskContext)10 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)9 MaterializedResult (com.facebook.presto.testing.MaterializedResult)9 QueryId (com.facebook.presto.spi.QueryId)7 List (java.util.List)7 Session (com.facebook.presto.Session)6 PipelineContext (com.facebook.presto.operator.PipelineContext)6 DataSize (io.airlift.units.DataSize)6 LocalExecutionPlan (com.facebook.presto.sql.planner.LocalExecutionPlanner.LocalExecutionPlan)5 Page (com.facebook.presto.common.Page)4 TaskStateMachine (com.facebook.presto.execution.TaskStateMachine)4 MemoryPool (com.facebook.presto.memory.MemoryPool)4 QueryContext (com.facebook.presto.memory.QueryContext)4 Driver (com.facebook.presto.operator.Driver)4 OperatorFactory (com.facebook.presto.operator.OperatorFactory)4