Search in sources :

Example 1 with Operator

use of io.trino.operator.Operator 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 2 with Operator

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

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 : OperatorAssertion.assertOperatorEquals(io.trino.operator.OperatorAssertion.assertOperatorEquals) INNER(io.trino.sql.planner.plan.SpatialJoinNode.Type.INNER) JoinFilterFunctionCompiler(io.trino.sql.gen.JoinFilterFunctionCompiler) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Slices(io.airlift.slice.Slices) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) RowPagesBuilder.rowPagesBuilder(io.trino.RowPagesBuilder.rowPagesBuilder) GEOMETRY(io.trino.plugin.geospatial.GeometryType.GEOMETRY) INTEGER(io.trino.spi.type.IntegerType.INTEGER) StandardJoinFilterFunction(io.trino.operator.join.StandardJoinFilterFunction) GeoFunctions.stGeometryFromText(io.trino.plugin.geospatial.GeoFunctions.stGeometryFromText) Operator(io.trino.operator.Operator) SynchronousQueue(java.util.concurrent.SynchronousQueue) KdbTree(io.trino.geospatial.KdbTree) SpatialPredicate(io.trino.operator.SpatialIndexBuilderOperator.SpatialPredicate) BeforeMethod(org.testng.annotations.BeforeMethod) PipelineContext(io.trino.operator.PipelineContext) TrinoException(io.trino.spi.TrinoException) Collections.emptyIterator(java.util.Collections.emptyIterator) Assert.assertNotNull(org.testng.Assert.assertNotNull) List(java.util.List) GeoFunctions.stPoint(io.trino.plugin.geospatial.GeoFunctions.stPoint) DriverContext(io.trino.operator.DriverContext) RowPagesBuilder(io.trino.RowPagesBuilder) InternalJoinFilterFunction(io.trino.operator.join.InternalJoinFilterFunction) LEFT(io.trino.sql.planner.plan.SpatialJoinNode.Type.LEFT) Optional(java.util.Optional) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Slice(io.airlift.slice.Slice) Type(io.trino.sql.planner.plan.SpatialJoinNode.Type) DataProvider(org.testng.annotations.DataProvider) Assert.assertNull(org.testng.Assert.assertNull) Rectangle(io.trino.geospatial.Rectangle) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) PagesSpatialIndex(io.trino.operator.PagesSpatialIndex) PagesSpatialIndexFactory(io.trino.operator.PagesSpatialIndexFactory) Page(io.trino.spi.Page) Assert.assertEquals(org.testng.Assert.assertEquals) KdbTreeUtils(io.trino.geospatial.KdbTreeUtils) TestingTaskContext(io.trino.testing.TestingTaskContext) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) TestingFactory(io.trino.operator.PagesIndex.TestingFactory) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) ValuesOperator(io.trino.operator.ValuesOperator) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TaskContext(io.trino.operator.TaskContext) ExecutorService(java.util.concurrent.ExecutorService) OperatorFactory(io.trino.operator.OperatorFactory) OperatorAssertion.toPages(io.trino.operator.OperatorAssertion.toPages) Node.newLeaf(io.trino.geospatial.KdbTree.Node.newLeaf) Node.newInternal(io.trino.geospatial.KdbTree.Node.newInternal) Ints(com.google.common.primitives.Ints) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) SpatialIndexBuilderOperatorFactory(io.trino.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) Assert.assertTrue(org.testng.Assert.assertTrue) SpatialJoinOperatorFactory(io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) Driver(io.trino.operator.Driver) SECONDS(java.util.concurrent.TimeUnit.SECONDS) MaterializedResult.resultBuilder(io.trino.testing.MaterializedResult.resultBuilder) 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) Page(io.trino.spi.Page) InternalJoinFilterFunction(io.trino.operator.join.InternalJoinFilterFunction) GeoFunctions.stPoint(io.trino.plugin.geospatial.GeoFunctions.stPoint) SpatialJoinOperatorFactory(io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OperatorFactory(io.trino.operator.OperatorFactory) SpatialIndexBuilderOperatorFactory(io.trino.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) SpatialJoinOperatorFactory(io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) PagesSpatialIndexFactory(io.trino.operator.PagesSpatialIndexFactory) Test(org.testng.annotations.Test)

Example 3 with Operator

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

the class TestHashJoinOperator method testInnerJoinWithBlockingLookupSource.

@Test(dataProvider = "hashJoinTestValues")
public void testInnerJoinWithBlockingLookupSource(boolean parallelBuild, boolean probeHashEnabled, boolean buildHashEnabled) throws Exception {
    RowPagesBuilder probePages = rowPagesBuilder(probeHashEnabled, Ints.asList(0), ImmutableList.of(VARCHAR));
    Page probePage = getOnlyElement(probePages.addSequencePage(1, 0).build());
    // join that waits for build side to be collected
    TaskContext taskContext = createTaskContext();
    OperatorFactory joinOperatorFactory = createJoinOperatorFactoryWithBlockingLookupSource(taskContext, parallelBuild, probeHashEnabled, buildHashEnabled, true);
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    try (Operator joinOperator = joinOperatorFactory.createOperator(driverContext)) {
        joinOperatorFactory.noMoreOperators();
        assertFalse(joinOperator.needsInput());
        assertNull(joinOperator.getOutput());
        // lookup join operator got blocked waiting for build side
        assertFalse(joinOperator.isBlocked().isDone());
        assertFalse(joinOperator.isFinished());
    }
    // join that doesn't wait for build side to be collected
    taskContext = createTaskContext();
    joinOperatorFactory = createJoinOperatorFactoryWithBlockingLookupSource(taskContext, parallelBuild, probeHashEnabled, buildHashEnabled, false);
    driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    try (Operator joinOperator = joinOperatorFactory.createOperator(driverContext)) {
        joinOperatorFactory.noMoreOperators();
        assertTrue(joinOperator.needsInput());
        assertNull(joinOperator.getOutput());
        // join needs input page
        assertTrue(joinOperator.isBlocked().isDone());
        assertFalse(joinOperator.isFinished());
        joinOperator.addInput(probePage);
        assertNull(joinOperator.getOutput());
        // lookup join operator got blocked waiting for build side
        assertFalse(joinOperator.isBlocked().isDone());
        assertFalse(joinOperator.isFinished());
    }
}
Also used : WorkProcessorOperator(io.trino.operator.WorkProcessorOperator) Operator(io.trino.operator.Operator) DriverContext(io.trino.operator.DriverContext) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) WorkProcessorOperatorFactory(io.trino.operator.WorkProcessorOperatorFactory) ValuesOperatorFactory(io.trino.operator.ValuesOperator.ValuesOperatorFactory) PageBufferOperatorFactory(io.trino.operator.index.PageBufferOperator.PageBufferOperatorFactory) JoinTestUtils.innerJoinOperatorFactory(io.trino.operator.join.JoinTestUtils.innerJoinOperatorFactory) OperatorFactory(io.trino.operator.OperatorFactory) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 4 with Operator

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

the class TestHashJoinOperator method innerJoinWithSpill.

private void innerJoinWithSpill(boolean probeHashEnabled, List<WhenSpill> whenSpill, SingleStreamSpillerFactory buildSpillerFactory, PartitioningSpillerFactory joinSpillerFactory) throws Exception {
    TaskStateMachine taskStateMachine = new TaskStateMachine(new TaskId(new StageId("query", 0), 0, 0), executor);
    TaskContext taskContext = TestingTaskContext.createTaskContext(executor, scheduledExecutor, TEST_SESSION, taskStateMachine);
    DriverContext joinDriverContext = taskContext.addPipelineContext(2, true, true, false).addDriverContext();
    // force a yield for every match in LookupJoinOperator, set called to true after first
    AtomicBoolean called = new AtomicBoolean(false);
    InternalJoinFilterFunction filterFunction = new TestInternalJoinFilterFunction((leftPosition, leftPage, rightPosition, rightPage) -> {
        called.set(true);
        joinDriverContext.getYieldSignal().forceYieldForTesting();
        return true;
    });
    // build factory
    RowPagesBuilder buildPages = rowPagesBuilder(false, Ints.asList(0), ImmutableList.of(VARCHAR, BIGINT)).addSequencePage(4, 20, 200).addSequencePage(4, 20, 200).addSequencePage(4, 30, 300).addSequencePage(4, 40, 400);
    BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, true, taskContext, buildPages, Optional.of(filterFunction), true, buildSpillerFactory);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactoryManager = buildSideSetup.getLookupSourceFactoryManager();
    // probe factory
    RowPagesBuilder probePages = rowPagesBuilder(probeHashEnabled, Ints.asList(0), ImmutableList.of(VARCHAR, BIGINT)).row("20", 123_000L).row("20", 123_000L).pageBreak().addSequencePage(20, 0, 123_000).addSequencePage(10, 30, 123_000);
    OperatorFactory joinOperatorFactory = innerJoinOperatorFactory(operatorFactories, lookupSourceFactoryManager, probePages, joinSpillerFactory, true);
    // build drivers and operators
    instantiateBuildDrivers(buildSideSetup, taskContext);
    List<Driver> buildDrivers = buildSideSetup.getBuildDrivers();
    int buildOperatorCount = buildDrivers.size();
    checkState(buildOperatorCount == whenSpill.size());
    LookupSourceFactory lookupSourceFactory = lookupSourceFactoryManager.getJoinBridge(Lifespan.taskWide());
    try (Operator joinOperator = joinOperatorFactory.createOperator(joinDriverContext)) {
        // build lookup source
        ListenableFuture<LookupSourceProvider> lookupSourceProvider = lookupSourceFactory.createLookupSourceProvider();
        List<Boolean> revoked = new ArrayList<>(nCopies(buildOperatorCount, false));
        while (!lookupSourceProvider.isDone()) {
            for (int i = 0; i < buildOperatorCount; i++) {
                checkErrors(taskStateMachine);
                buildDrivers.get(i).process();
                HashBuilderOperator buildOperator = buildSideSetup.getBuildOperators().get(i);
                if (whenSpill.get(i) == WhenSpill.DURING_BUILD && buildOperator.getOperatorContext().getReservedRevocableBytes() > 0) {
                    checkState(!lookupSourceProvider.isDone(), "Too late, LookupSource already done");
                    revokeMemory(buildOperator);
                    revoked.set(i, true);
                }
            }
        }
        getFutureValue(lookupSourceProvider).close();
        assertEquals(revoked, whenSpill.stream().map(WhenSpill.DURING_BUILD::equals).collect(toImmutableList()), "Some operators not spilled before LookupSource built");
        for (int i = 0; i < buildOperatorCount; i++) {
            if (whenSpill.get(i) == WhenSpill.AFTER_BUILD) {
                revokeMemory(buildSideSetup.getBuildOperators().get(i));
            }
        }
        for (Driver buildDriver : buildDrivers) {
            runDriverInThread(executor, buildDriver);
        }
        ValuesOperatorFactory valuesOperatorFactory = new ValuesOperatorFactory(17, new PlanNodeId("values"), probePages.build());
        PageBuffer pageBuffer = new PageBuffer(10);
        PageBufferOperatorFactory pageBufferOperatorFactory = new PageBufferOperatorFactory(18, new PlanNodeId("pageBuffer"), pageBuffer);
        Driver joinDriver = Driver.createDriver(joinDriverContext, valuesOperatorFactory.createOperator(joinDriverContext), joinOperator, pageBufferOperatorFactory.createOperator(joinDriverContext));
        while (!called.get()) {
            // process first row of first page of LookupJoinOperator
            processRow(joinDriver, taskStateMachine);
        }
        for (int i = 0; i < buildOperatorCount; i++) {
            if (whenSpill.get(i) == WhenSpill.DURING_USAGE) {
                triggerMemoryRevokingAndWait(buildSideSetup.getBuildOperators().get(i), taskStateMachine);
            }
        }
        // process remaining LookupJoinOperator pages
        while (!joinDriver.isFinished()) {
            checkErrors(taskStateMachine);
            processRow(joinDriver, taskStateMachine);
        }
        checkErrors(taskStateMachine);
        List<Page> actualPages = getPages(pageBuffer);
        MaterializedResult expected = MaterializedResult.resultBuilder(taskContext.getSession(), concat(probePages.getTypesWithoutHash(), buildPages.getTypesWithoutHash())).row("20", 123_000L, "20", 200L).row("20", 123_000L, "20", 200L).row("20", 123_000L, "20", 200L).row("20", 123_000L, "20", 200L).row("30", 123_000L, "30", 300L).row("31", 123_001L, "31", 301L).row("32", 123_002L, "32", 302L).row("33", 123_003L, "33", 303L).build();
        assertEqualsIgnoreOrder(getProperColumns(joinOperator, concat(probePages.getTypes(), buildPages.getTypes()), probePages, actualPages).getMaterializedRows(), expected.getMaterializedRows());
    } finally {
        joinOperatorFactory.noMoreOperators();
    }
}
Also used : WorkProcessorOperator(io.trino.operator.WorkProcessorOperator) Operator(io.trino.operator.Operator) DriverContext(io.trino.operator.DriverContext) TaskId(io.trino.execution.TaskId) StageId(io.trino.execution.StageId) ArrayList(java.util.ArrayList) Driver(io.trino.operator.Driver) Page(io.trino.spi.Page) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) TaskStateMachine(io.trino.execution.TaskStateMachine) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) BuildSideSetup(io.trino.operator.join.JoinTestUtils.BuildSideSetup) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PageBuffer(io.trino.operator.index.PageBuffer) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) RowPagesBuilder(io.trino.RowPagesBuilder) PageBufferOperatorFactory(io.trino.operator.index.PageBufferOperator.PageBufferOperatorFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WorkProcessorOperatorFactory(io.trino.operator.WorkProcessorOperatorFactory) ValuesOperatorFactory(io.trino.operator.ValuesOperator.ValuesOperatorFactory) PageBufferOperatorFactory(io.trino.operator.index.PageBufferOperator.PageBufferOperatorFactory) JoinTestUtils.innerJoinOperatorFactory(io.trino.operator.join.JoinTestUtils.innerJoinOperatorFactory) OperatorFactory(io.trino.operator.OperatorFactory) ValuesOperatorFactory(io.trino.operator.ValuesOperator.ValuesOperatorFactory) MaterializedResult(io.trino.testing.MaterializedResult)

Example 5 with Operator

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

the class BenchmarkHashBuildAndJoinOperators method buildHash.

private static void buildHash(BuildContext buildContext, JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactoryManager, List<Integer> outputChannels, int partitionCount) {
    HashBuilderOperatorFactory hashBuilderOperatorFactory = new HashBuilderOperatorFactory(HASH_BUILD_OPERATOR_ID, TEST_PLAN_NODE_ID, lookupSourceFactoryManager, outputChannels, buildContext.getHashChannels(), buildContext.getHashChannel(), Optional.empty(), Optional.empty(), ImmutableList.of(), 10_000, new PagesIndex.TestingFactory(false), false, SingleStreamSpillerFactory.unsupportedSingleStreamSpillerFactory(), incrementalLoadFactorHashArraySizeSupplier(buildContext.getSession()));
    Operator[] operators = IntStream.range(0, partitionCount).mapToObj(i -> buildContext.createTaskContext().addPipelineContext(0, true, true, partitionCount > 1).addDriverContext()).map(hashBuilderOperatorFactory::createOperator).toArray(Operator[]::new);
    if (partitionCount == 1) {
        for (Page page : buildContext.getBuildPages()) {
            operators[0].addInput(page);
        }
    } else {
        PartitionFunction partitionGenerator = new LocalPartitionGenerator(new InterpretedHashGenerator(buildContext.getHashChannels().stream().map(channel -> buildContext.getTypes().get(channel)).collect(toImmutableList()), buildContext.getHashChannels(), TYPE_OPERATOR_FACTORY), partitionCount);
        for (Page page : buildContext.getBuildPages()) {
            Page[] partitionedPages = partitionPages(page, buildContext.getTypes(), partitionCount, partitionGenerator);
            for (int i = 0; i < partitionCount; i++) {
                operators[i].addInput(partitionedPages[i]);
            }
        }
    }
    LookupSourceFactory lookupSourceFactory = lookupSourceFactoryManager.getJoinBridge(Lifespan.taskWide());
    ListenableFuture<LookupSourceProvider> lookupSourceProvider = lookupSourceFactory.createLookupSourceProvider();
    for (Operator operator : operators) {
        operator.finish();
    }
    if (!lookupSourceProvider.isDone()) {
        throw new AssertionError("Expected lookup source provider to be ready");
    }
    getFutureValue(lookupSourceProvider).close();
}
Also used : Operator(io.trino.operator.Operator) PartitionFunction(io.trino.operator.PartitionFunction) JoinBridgeManager.lookupAllAtOnce(io.trino.operator.join.JoinBridgeManager.lookupAllAtOnce) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Arrays(java.util.Arrays) Test(org.testng.annotations.Test) Random(java.util.Random) AverageTime(org.openjdk.jmh.annotations.Mode.AverageTime) TypeOperators(io.trino.spi.type.TypeOperators) Warmup(org.openjdk.jmh.annotations.Warmup) HashBuilderOperatorFactory(io.trino.operator.join.HashBuilderOperator.HashBuilderOperatorFactory) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) RowPagesBuilder.rowPagesBuilder(io.trino.RowPagesBuilder.rowPagesBuilder) RunnerException(org.openjdk.jmh.runner.RunnerException) Setup(org.openjdk.jmh.annotations.Setup) Operator(io.trino.operator.Operator) Param(org.openjdk.jmh.annotations.Param) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Benchmarks.benchmark(io.trino.jmh.Benchmarks.benchmark) TrinoOperatorFactories(io.trino.operator.TrinoOperatorFactories) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) HashArraySizeSupplier.incrementalLoadFactorHashArraySizeSupplier(io.trino.operator.HashArraySizeSupplier.incrementalLoadFactorHashArraySizeSupplier) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) DataSize(io.airlift.units.DataSize) List(java.util.List) DriverContext(io.trino.operator.DriverContext) BIGINT(io.trino.spi.type.BigintType.BIGINT) RowPagesBuilder(io.trino.RowPagesBuilder) Optional(java.util.Optional) Session(io.trino.Session) IntStream(java.util.stream.IntStream) OperatorFactories(io.trino.operator.OperatorFactories) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Measurement(org.openjdk.jmh.annotations.Measurement) PageBuilder(io.trino.spi.PageBuilder) Type(io.trino.spi.type.Type) Page(io.trino.spi.Page) Scope(org.openjdk.jmh.annotations.Scope) OptionalInt(java.util.OptionalInt) LocalPartitionGenerator(io.trino.operator.exchange.LocalPartitionGenerator) TestingTaskContext(io.trino.testing.TestingTaskContext) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TaskContext(io.trino.operator.TaskContext) Lifespan(io.trino.execution.Lifespan) Threads(org.openjdk.jmh.annotations.Threads) ExecutorService(java.util.concurrent.ExecutorService) PartitioningSpillerFactory.unsupportedPartitioningSpillerFactory(io.trino.spiller.PartitioningSpillerFactory.unsupportedPartitioningSpillerFactory) OperatorFactory(io.trino.operator.OperatorFactory) PagesIndex(io.trino.operator.PagesIndex) InterpretedHashGenerator(io.trino.operator.InterpretedHashGenerator) PartitionFunction(io.trino.operator.PartitionFunction) BlockTypeOperators(io.trino.type.BlockTypeOperators) Iterator(java.util.Iterator) SingleStreamSpillerFactory(io.trino.spiller.SingleStreamSpillerFactory) State(org.openjdk.jmh.annotations.State) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) Ints(com.google.common.primitives.Ints) Benchmark(org.openjdk.jmh.annotations.Benchmark) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Fork(org.openjdk.jmh.annotations.Fork) SECONDS(java.util.concurrent.TimeUnit.SECONDS) InterpretedHashGenerator(io.trino.operator.InterpretedHashGenerator) LocalPartitionGenerator(io.trino.operator.exchange.LocalPartitionGenerator) HashBuilderOperatorFactory(io.trino.operator.join.HashBuilderOperator.HashBuilderOperatorFactory) Page(io.trino.spi.Page) PagesIndex(io.trino.operator.PagesIndex)

Aggregations

Operator (io.trino.operator.Operator)13 DriverContext (io.trino.operator.DriverContext)11 TaskContext (io.trino.operator.TaskContext)11 OperatorFactory (io.trino.operator.OperatorFactory)10 Page (io.trino.spi.Page)10 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)10 TestingTaskContext (io.trino.testing.TestingTaskContext)10 Test (org.testng.annotations.Test)10 RowPagesBuilder (io.trino.RowPagesBuilder)9 ValuesOperatorFactory (io.trino.operator.ValuesOperator.ValuesOperatorFactory)8 WorkProcessorOperator (io.trino.operator.WorkProcessorOperator)7 WorkProcessorOperatorFactory (io.trino.operator.WorkProcessorOperatorFactory)7 PageBufferOperatorFactory (io.trino.operator.index.PageBufferOperator.PageBufferOperatorFactory)7 JoinTestUtils.innerJoinOperatorFactory (io.trino.operator.join.JoinTestUtils.innerJoinOperatorFactory)7 ImmutableList (com.google.common.collect.ImmutableList)6 Driver (io.trino.operator.Driver)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 BuildSideSetup (io.trino.operator.join.JoinTestUtils.BuildSideSetup)5 Type (io.trino.spi.type.Type)5 List (java.util.List)5