Search in sources :

Example 1 with ProcessorContext

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

the class TestHashJoinOperator method testInnerJoinLoadsPagesInOrder.

@Test
public void testInnerJoinLoadsPagesInOrder() {
    TaskContext taskContext = createTaskContext();
    // build factory
    List<Type> buildTypes = ImmutableList.of(VARCHAR);
    RowPagesBuilder buildPages = rowPagesBuilder(false, Ints.asList(0), buildTypes);
    for (int i = 0; i < 100_000; ++i) {
        buildPages.row("a");
    }
    BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, false, taskContext, buildPages, Optional.empty(), false, SINGLE_STREAM_SPILLER_FACTORY);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager();
    // probe factory
    List<Type> probeTypes = ImmutableList.of(VARCHAR, INTEGER, INTEGER);
    RowPagesBuilder probePages = rowPagesBuilder(false, Ints.asList(0), probeTypes);
    probePages.row("a", 1L, 2L);
    WorkProcessorOperatorFactory joinOperatorFactory = (WorkProcessorOperatorFactory) innerJoinOperatorFactory(operatorFactories, lookupSourceFactory, probePages, PARTITIONING_SPILLER_FACTORY, false);
    // build drivers and operators
    instantiateBuildDrivers(buildSideSetup, taskContext);
    buildLookupSource(executor, buildSideSetup);
    Page probePage = getOnlyElement(probePages.build());
    AtomicInteger totalProbePages = new AtomicInteger();
    WorkProcessor<Page> inputPages = WorkProcessor.create(() -> {
        int probePageNumber = totalProbePages.incrementAndGet();
        if (probePageNumber == 5) {
            return finished();
        }
        return ofResult(new Page(1, probePage.getBlock(0), // this block should not be loaded by join operator as it's not being used by join
        new LazyBlock(1, () -> probePage.getBlock(1)), // and outputting current probe page
        new LazyBlock(1, () -> {
            // when loaded this block should be the latest one
            assertEquals(probePageNumber, totalProbePages.get());
            return probePage.getBlock(2);
        })));
    });
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    OperatorContext operatorContext = driverContext.addOperatorContext(joinOperatorFactory.getOperatorId(), joinOperatorFactory.getPlanNodeId(), joinOperatorFactory.getOperatorType());
    WorkProcessorOperator joinOperator = joinOperatorFactory.create(new ProcessorContext(taskContext.getSession(), taskContext.getTaskMemoryContext(), operatorContext), inputPages);
    WorkProcessor<Page> outputPages = joinOperator.getOutputPages();
    int totalOutputPages = 0;
    for (int i = 0; i < 1_000_000; ++i) {
        if (!outputPages.process()) {
            // allow join to progress
            driverContext.getYieldSignal().resetYieldForTesting();
            continue;
        }
        if (outputPages.isFinished()) {
            break;
        }
        Page page = outputPages.getResult();
        totalOutputPages++;
        assertFalse(page.getBlock(1).isLoaded());
        page.getBlock(2).getLoadedBlock();
        // yield to enforce more complex execution
        driverContext.getYieldSignal().forceYieldForTesting();
    }
    // make sure that multiple pages were produced for some probe pages
    assertTrue(totalOutputPages > totalProbePages.get());
    assertTrue(outputPages.isFinished());
}
Also used : DriverContext(io.trino.operator.DriverContext) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) WorkProcessorOperator(io.trino.operator.WorkProcessorOperator) Page(io.trino.spi.Page) ProcessorContext(io.trino.operator.ProcessorContext) WorkProcessorOperatorFactory(io.trino.operator.WorkProcessorOperatorFactory) Type(io.trino.spi.type.Type) LazyBlock(io.trino.spi.block.LazyBlock) BuildSideSetup(io.trino.operator.join.JoinTestUtils.BuildSideSetup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OperatorContext(io.trino.operator.OperatorContext) Test(org.testng.annotations.Test)

Aggregations

RowPagesBuilder (io.trino.RowPagesBuilder)1 DriverContext (io.trino.operator.DriverContext)1 OperatorContext (io.trino.operator.OperatorContext)1 ProcessorContext (io.trino.operator.ProcessorContext)1 TaskContext (io.trino.operator.TaskContext)1 WorkProcessorOperator (io.trino.operator.WorkProcessorOperator)1 WorkProcessorOperatorFactory (io.trino.operator.WorkProcessorOperatorFactory)1 BuildSideSetup (io.trino.operator.join.JoinTestUtils.BuildSideSetup)1 Page (io.trino.spi.Page)1 LazyBlock (io.trino.spi.block.LazyBlock)1 Type (io.trino.spi.type.Type)1 TestingTaskContext (io.trino.testing.TestingTaskContext)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.testng.annotations.Test)1