Search in sources :

Example 16 with OperatorFactory

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

the class TestHashJoinOperator method testProbeOuterJoinWithFilterFunction.

@Test(dataProvider = "hashJoinTestValues")
public void testProbeOuterJoinWithFilterFunction(boolean parallelBuild, boolean probeHashEnabled, boolean buildHashEnabled) {
    TaskContext taskContext = createTaskContext();
    InternalJoinFilterFunction filterFunction = new TestInternalJoinFilterFunction(((leftPosition, leftPage, rightPosition, rightPage) -> BIGINT.getLong(rightPage.getBlock(1), rightPosition) >= 1025));
    // build factory
    List<Type> buildTypes = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    RowPagesBuilder buildPages = rowPagesBuilder(buildHashEnabled, Ints.asList(0), ImmutableList.of(VARCHAR, BIGINT, BIGINT)).addSequencePage(10, 20, 30, 40);
    BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, parallelBuild, taskContext, buildPages, Optional.of(filterFunction), false, SINGLE_STREAM_SPILLER_FACTORY);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager();
    // probe factory
    List<Type> probeTypes = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    RowPagesBuilder probePages = rowPagesBuilder(probeHashEnabled, Ints.asList(0), probeTypes);
    List<Page> probeInput = probePages.addSequencePage(15, 20, 1020, 2020).build();
    OperatorFactory joinOperatorFactory = probeOuterJoinOperatorFactory(lookupSourceFactory, probePages, true);
    // build drivers and operators
    instantiateBuildDrivers(buildSideSetup, taskContext);
    buildLookupSource(executor, buildSideSetup);
    // expected
    MaterializedResult expected = MaterializedResult.resultBuilder(taskContext.getSession(), concat(probeTypes, buildTypes)).row("20", 1020L, 2020L, null, null, null).row("21", 1021L, 2021L, null, null, null).row("22", 1022L, 2022L, null, null, null).row("23", 1023L, 2023L, null, null, null).row("24", 1024L, 2024L, null, null, null).row("25", 1025L, 2025L, "25", 35L, 45L).row("26", 1026L, 2026L, "26", 36L, 46L).row("27", 1027L, 2027L, "27", 37L, 47L).row("28", 1028L, 2028L, "28", 38L, 48L).row("29", 1029L, 2029L, "29", 39L, 49L).row("30", 1030L, 2030L, null, null, null).row("31", 1031L, 2031L, null, null, null).row("32", 1032L, 2032L, null, null, null).row("33", 1033L, 2033L, null, null, null).row("34", 1034L, 2034L, null, null, null).build();
    assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true, false).addDriverContext(), probeInput, expected, true, getHashChannels(probePages, buildPages));
}
Also used : OperatorAssertion.assertOperatorEquals(io.trino.operator.OperatorAssertion.assertOperatorEquals) Arrays(java.util.Arrays) Test(org.testng.annotations.Test) TypeOperators(io.trino.spi.type.TypeOperators) TaskStateMachine(io.trino.execution.TaskStateMachine) AfterMethod(org.testng.annotations.AfterMethod) OperatorContext(io.trino.operator.OperatorContext) Collections.singletonList(java.util.Collections.singletonList) NodeScheduler(io.trino.execution.scheduler.NodeScheduler) FinalizerService(io.trino.util.FinalizerService) ExceededMemoryLimitException(io.trino.ExceededMemoryLimitException) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) BuildSideSetup(io.trino.operator.join.JoinTestUtils.BuildSideSetup) Arrays.asList(java.util.Arrays.asList) Slices(io.airlift.slice.Slices) WorkProcessor(io.trino.operator.WorkProcessor) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) ProcessState.finished(io.trino.operator.WorkProcessor.ProcessState.finished) Assert.assertFalse(org.testng.Assert.assertFalse) Assert.assertEquals(io.trino.testing.assertions.Assert.assertEquals) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) NodeSchedulerConfig(io.trino.execution.scheduler.NodeSchedulerConfig) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TrinoOperatorFactories(io.trino.operator.TrinoOperatorFactories) WorkProcessorOperatorFactory(io.trino.operator.WorkProcessorOperatorFactory) ProcessState.ofResult(io.trino.operator.WorkProcessor.ProcessState.ofResult) RowPagesBuilder(io.trino.RowPagesBuilder) OperatorAssertion.without(io.trino.operator.OperatorAssertion.without) InMemoryNodeManager(io.trino.metadata.InMemoryNodeManager) ValuesOperatorFactory(io.trino.operator.ValuesOperator.ValuesOperatorFactory) Iterables(com.google.common.collect.Iterables) StageId(io.trino.execution.StageId) Page(io.trino.spi.Page) NodePartitioningManager(io.trino.sql.planner.NodePartitioningManager) JoinTestUtils.getHashChannelAsInt(io.trino.operator.join.JoinTestUtils.getHashChannelAsInt) ArrayList(java.util.ArrayList) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) WorkProcessorOperator(io.trino.operator.WorkProcessorOperator) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Lifespan(io.trino.execution.Lifespan) BlockTypeOperators(io.trino.type.BlockTypeOperators) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) MoreFutures.getFutureValue(io.airlift.concurrent.MoreFutures.getFutureValue) JoinTestUtils.instantiateBuildDrivers(io.trino.operator.join.JoinTestUtils.instantiateBuildDrivers) Driver(io.trino.operator.Driver) NodeTaskMap(io.trino.execution.NodeTaskMap) MaterializedResult(io.trino.testing.MaterializedResult) PageBufferOperatorFactory(io.trino.operator.index.PageBufferOperator.PageBufferOperatorFactory) JoinTestUtils.innerJoinOperatorFactory(io.trino.operator.join.JoinTestUtils.innerJoinOperatorFactory) LazyBlock(io.trino.spi.block.LazyBlock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowPagesBuilder.rowPagesBuilder(io.trino.RowPagesBuilder.rowPagesBuilder) INTEGER(io.trino.spi.type.IntegerType.INTEGER) OperatorAssertion.dropChannel(io.trino.operator.OperatorAssertion.dropChannel) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) ImmutableSet(com.google.common.collect.ImmutableSet) Operator(io.trino.operator.Operator) SynchronousQueue(java.util.concurrent.SynchronousQueue) Collections.nCopies(java.util.Collections.nCopies) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) TaskId(io.trino.execution.TaskId) UniformNodeSelectorFactory(io.trino.execution.scheduler.UniformNodeSelectorFactory) 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) Optional(java.util.Optional) JoinTestUtils.setupBuildSide(io.trino.operator.join.JoinTestUtils.setupBuildSide) OperatorFactories(io.trino.operator.OperatorFactories) PageBuffer(io.trino.operator.index.PageBuffer) ProcessorContext(io.trino.operator.ProcessorContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DataProvider(org.testng.annotations.DataProvider) Assert.assertNull(org.testng.Assert.assertNull) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Type(io.trino.spi.type.Type) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JoinTestUtils.runDriverInThread(io.trino.operator.join.JoinTestUtils.runDriverInThread) OptionalInt(java.util.OptionalInt) TestingTaskContext(io.trino.testing.TestingTaskContext) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) Objects.requireNonNull(java.util.Objects.requireNonNull) TaskContext(io.trino.operator.TaskContext) GenericPartitioningSpillerFactory(io.trino.spiller.GenericPartitioningSpillerFactory) ExecutorService(java.util.concurrent.ExecutorService) OperatorFactory(io.trino.operator.OperatorFactory) OperatorAssertion(io.trino.operator.OperatorAssertion) SingleStreamSpillerFactory(io.trino.spiller.SingleStreamSpillerFactory) Ints(com.google.common.primitives.Ints) TimeUnit(java.util.concurrent.TimeUnit) PartitioningSpillerFactory(io.trino.spiller.PartitioningSpillerFactory) Assertions.assertEqualsIgnoreOrder(io.airlift.testing.Assertions.assertEqualsIgnoreOrder) Collectors.toList(java.util.stream.Collectors.toList) DummySpillerFactory(io.trino.operator.join.JoinTestUtils.DummySpillerFactory) JoinTestUtils.buildLookupSource(io.trino.operator.join.JoinTestUtils.buildLookupSource) Assert.assertTrue(org.testng.Assert.assertTrue) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) RowPagesBuilder(io.trino.RowPagesBuilder) Page(io.trino.spi.Page) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) Type(io.trino.spi.type.Type) BuildSideSetup(io.trino.operator.join.JoinTestUtils.BuildSideSetup) 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) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 17 with OperatorFactory

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

the class TestHashJoinOperator method testProbeOuterJoin.

@Test(dataProvider = "hashJoinTestValues")
public void testProbeOuterJoin(boolean parallelBuild, boolean probeHashEnabled, boolean buildHashEnabled) {
    TaskContext taskContext = createTaskContext();
    // build factory
    List<Type> buildTypes = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    RowPagesBuilder buildPages = rowPagesBuilder(buildHashEnabled, Ints.asList(0), ImmutableList.of(VARCHAR, BIGINT, BIGINT)).addSequencePage(10, 20, 30, 40);
    BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, parallelBuild, taskContext, buildPages, Optional.empty(), false, SINGLE_STREAM_SPILLER_FACTORY);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager();
    // probe factory
    List<Type> probeTypes = ImmutableList.of(VARCHAR, BIGINT, BIGINT);
    RowPagesBuilder probePages = rowPagesBuilder(probeHashEnabled, Ints.asList(0), probeTypes);
    List<Page> probeInput = probePages.addSequencePage(15, 20, 1020, 2020).build();
    OperatorFactory joinOperatorFactory = probeOuterJoinOperatorFactory(lookupSourceFactory, probePages, false);
    // build drivers and operators
    instantiateBuildDrivers(buildSideSetup, taskContext);
    buildLookupSource(executor, buildSideSetup);
    // expected
    MaterializedResult expected = MaterializedResult.resultBuilder(taskContext.getSession(), concat(probeTypes, buildTypes)).row("20", 1020L, 2020L, "20", 30L, 40L).row("21", 1021L, 2021L, "21", 31L, 41L).row("22", 1022L, 2022L, "22", 32L, 42L).row("23", 1023L, 2023L, "23", 33L, 43L).row("24", 1024L, 2024L, "24", 34L, 44L).row("25", 1025L, 2025L, "25", 35L, 45L).row("26", 1026L, 2026L, "26", 36L, 46L).row("27", 1027L, 2027L, "27", 37L, 47L).row("28", 1028L, 2028L, "28", 38L, 48L).row("29", 1029L, 2029L, "29", 39L, 49L).row("30", 1030L, 2030L, null, null, null).row("31", 1031L, 2031L, null, null, null).row("32", 1032L, 2032L, null, null, null).row("33", 1033L, 2033L, null, null, null).row("34", 1034L, 2034L, null, null, null).build();
    assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true, false).addDriverContext(), probeInput, expected, true, getHashChannels(probePages, buildPages));
}
Also used : Type(io.trino.spi.type.Type) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) BuildSideSetup(io.trino.operator.join.JoinTestUtils.BuildSideSetup) 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) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 18 with OperatorFactory

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

the class TestHashJoinOperator method testProbeOuterJoinWithEmptyLookupSource.

@Test(dataProvider = "hashJoinTestValues")
public void testProbeOuterJoinWithEmptyLookupSource(boolean parallelBuild, boolean probeHashEnabled, boolean buildHashEnabled) {
    TaskContext taskContext = createTaskContext();
    // build factory
    List<Type> buildTypes = ImmutableList.of(VARCHAR);
    RowPagesBuilder buildPages = rowPagesBuilder(buildHashEnabled, Ints.asList(0), buildTypes);
    BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, parallelBuild, taskContext, buildPages, Optional.empty(), false, SINGLE_STREAM_SPILLER_FACTORY);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactoryManager = buildSideSetup.getLookupSourceFactoryManager();
    // probe factory
    List<Type> probeTypes = ImmutableList.of(VARCHAR);
    RowPagesBuilder probePages = rowPagesBuilder(probeHashEnabled, Ints.asList(0), probeTypes);
    List<Page> probeInput = probePages.row("a").row("b").row((String) null).row("c").build();
    OperatorFactory joinOperatorFactory = operatorFactories.probeOuterJoin(0, new PlanNodeId("test"), lookupSourceFactoryManager, false, false, probePages.getTypes(), Ints.asList(0), getHashChannelAsInt(probePages), Optional.empty(), OptionalInt.of(1), PARTITIONING_SPILLER_FACTORY, TYPE_OPERATOR_FACTORY);
    // build drivers and operators
    instantiateBuildDrivers(buildSideSetup, taskContext);
    buildLookupSource(executor, buildSideSetup);
    // expected
    MaterializedResult expected = MaterializedResult.resultBuilder(taskContext.getSession(), concat(probeTypes, buildTypes)).row("a", null).row("b", null).row(null, null).row("c", null).build();
    assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true, false).addDriverContext(), probeInput, expected, true, getHashChannels(probePages, buildPages));
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) BuildSideSetup(io.trino.operator.join.JoinTestUtils.BuildSideSetup) 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) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 19 with OperatorFactory

use of io.trino.operator.OperatorFactory 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 20 with OperatorFactory

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

the class TestHashJoinOperator method testOuterJoinWithNullBuild.

@Test(dataProvider = "hashJoinTestValues")
public void testOuterJoinWithNullBuild(boolean parallelBuild, boolean probeHashEnabled, boolean buildHashEnabled) {
    TaskContext taskContext = createTaskContext();
    // build factory
    List<Type> buildTypes = ImmutableList.of(VARCHAR);
    RowPagesBuilder buildPages = rowPagesBuilder(buildHashEnabled, Ints.asList(0), ImmutableList.of(VARCHAR)).row("a").row((String) null).row((String) null).row("a").row("b");
    BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, parallelBuild, taskContext, buildPages, Optional.empty(), false, SINGLE_STREAM_SPILLER_FACTORY);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager();
    // probe factory
    List<Type> probeTypes = ImmutableList.of(VARCHAR);
    RowPagesBuilder probePages = rowPagesBuilder(probeHashEnabled, Ints.asList(0), probeTypes);
    List<Page> probeInput = probePages.row("a").row("b").row("c").build();
    OperatorFactory joinOperatorFactory = probeOuterJoinOperatorFactory(lookupSourceFactory, probePages, false);
    // build drivers and operators
    instantiateBuildDrivers(buildSideSetup, taskContext);
    buildLookupSource(executor, buildSideSetup);
    // expected
    MaterializedResult expected = MaterializedResult.resultBuilder(taskContext.getSession(), concat(probeTypes, buildTypes)).row("a", "a").row("a", "a").row("b", "b").row("c", null).build();
    assertOperatorEquals(joinOperatorFactory, taskContext.addPipelineContext(0, true, true, false).addDriverContext(), probeInput, expected, true, getHashChannels(probePages, buildPages));
}
Also used : Type(io.trino.spi.type.Type) TestingTaskContext(io.trino.testing.TestingTaskContext) TaskContext(io.trino.operator.TaskContext) RowPagesBuilder(io.trino.RowPagesBuilder) BuildSideSetup(io.trino.operator.join.JoinTestUtils.BuildSideSetup) 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) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Aggregations

OperatorFactory (io.trino.operator.OperatorFactory)54 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)38 Test (org.testng.annotations.Test)35 MaterializedResult (io.trino.testing.MaterializedResult)34 Type (io.trino.spi.type.Type)33 Page (io.trino.spi.Page)31 RowPagesBuilder (io.trino.RowPagesBuilder)29 TaskContext (io.trino.operator.TaskContext)29 TestingTaskContext (io.trino.testing.TestingTaskContext)29 ValuesOperatorFactory (io.trino.operator.ValuesOperator.ValuesOperatorFactory)26 PageBufferOperatorFactory (io.trino.operator.index.PageBufferOperator.PageBufferOperatorFactory)26 WorkProcessorOperatorFactory (io.trino.operator.WorkProcessorOperatorFactory)25 JoinTestUtils.innerJoinOperatorFactory (io.trino.operator.join.JoinTestUtils.innerJoinOperatorFactory)25 BuildSideSetup (io.trino.operator.join.JoinTestUtils.BuildSideSetup)23 DriverContext (io.trino.operator.DriverContext)17 Operator (io.trino.operator.Operator)13 ImmutableList (com.google.common.collect.ImmutableList)11 Driver (io.trino.operator.Driver)11 WorkProcessorOperator (io.trino.operator.WorkProcessorOperator)11 ArrayList (java.util.ArrayList)10