Search in sources :

Example 21 with DriverContext

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

the class TestMemoryPools method setupConsumeRevocableMemory.

private RevocableMemoryOperator setupConsumeRevocableMemory(DataSize reservedPerPage, long numberOfPages) {
    AtomicReference<RevocableMemoryOperator> createOperator = new AtomicReference<>();
    setUp(() -> {
        DriverContext driverContext = taskContext.addPipelineContext(0, false, false, false).addDriverContext();
        OperatorContext revokableOperatorContext = driverContext.addOperatorContext(Integer.MAX_VALUE, new PlanNodeId("revokable_operator"), TableScanOperator.class.getSimpleName());
        OutputFactory outputFactory = new PageConsumerOutputFactory(types -> (page -> {
        }));
        Operator outputOperator = outputFactory.createOutputOperator(2, new PlanNodeId("output"), ImmutableList.of(), Function.identity(), new TestingPagesSerdeFactory()).createOperator(driverContext);
        RevocableMemoryOperator revocableMemoryOperator = new RevocableMemoryOperator(revokableOperatorContext, reservedPerPage, numberOfPages);
        createOperator.set(revocableMemoryOperator);
        Driver driver = Driver.createDriver(driverContext, revocableMemoryOperator, outputOperator);
        return ImmutableList.of(driver);
    });
    return createOperator.get();
}
Also used : QueryId(io.trino.spi.QueryId) SpillSpaceTracker(io.trino.spiller.SpillSpaceTracker) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Page(io.trino.spi.Page) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) OperatorContext(io.trino.operator.OperatorContext) GIGABYTE(io.airlift.units.DataSize.Unit.GIGABYTE) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TpchConnectorFactory(io.trino.plugin.tpch.TpchConnectorFactory) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Map(java.util.Map) TaskContext(io.trino.operator.TaskContext) PageConsumerOutputFactory(io.trino.testing.PageConsumerOperator.PageConsumerOutputFactory) Assert.assertFalse(org.testng.Assert.assertFalse) TestingPagesSerdeFactory(io.trino.execution.buffer.TestingPagesSerdeFactory) TestingTaskContext.createTaskContext(io.trino.testing.TestingTaskContext.createTaskContext) Futures.immediateVoidFuture(com.google.common.util.concurrent.Futures.immediateVoidFuture) Operator(io.trino.operator.Operator) ImmutableMap(com.google.common.collect.ImmutableMap) TableScanOperator(io.trino.operator.TableScanOperator) Predicate(java.util.function.Predicate) OutputFactory(io.trino.operator.OutputFactory) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) AtomicLong(java.util.concurrent.atomic.AtomicLong) DataSize(io.airlift.units.DataSize) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) DriverContext(io.trino.operator.DriverContext) Assert.assertTrue(org.testng.Assert.assertTrue) LocalMemoryContext(io.trino.memory.context.LocalMemoryContext) Driver(io.trino.operator.Driver) TestingGcMonitor(io.airlift.stats.TestingGcMonitor) Session(io.trino.Session) Operator(io.trino.operator.Operator) TableScanOperator(io.trino.operator.TableScanOperator) DriverContext(io.trino.operator.DriverContext) TableScanOperator(io.trino.operator.TableScanOperator) PageConsumerOutputFactory(io.trino.testing.PageConsumerOperator.PageConsumerOutputFactory) TestingPagesSerdeFactory(io.trino.execution.buffer.TestingPagesSerdeFactory) Driver(io.trino.operator.Driver) AtomicReference(java.util.concurrent.atomic.AtomicReference) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) OperatorContext(io.trino.operator.OperatorContext) PageConsumerOutputFactory(io.trino.testing.PageConsumerOperator.PageConsumerOutputFactory) OutputFactory(io.trino.operator.OutputFactory)

Example 22 with DriverContext

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

the class LocalQueryRunner method createDrivers.

private List<Driver> createDrivers(Session session, Plan plan, OutputFactory outputFactory, TaskContext taskContext) {
    if (printPlan) {
        System.out.println(PlanPrinter.textLogicalPlan(plan.getRoot(), plan.getTypes(), plannerContext.getMetadata(), plannerContext.getFunctionManager(), plan.getStatsAndCosts(), session, 0, false));
    }
    SubPlan subplan = createSubPlans(session, plan, true);
    if (!subplan.getChildren().isEmpty()) {
        throw new AssertionError("Expected subplan to have no children");
    }
    TableExecuteContextManager tableExecuteContextManager = new TableExecuteContextManager();
    tableExecuteContextManager.registerTableExecuteContextForQuery(taskContext.getQueryContext().getQueryId());
    LocalExecutionPlanner executionPlanner = new LocalExecutionPlanner(plannerContext, new TypeAnalyzer(plannerContext, statementAnalyzerFactory), Optional.empty(), pageSourceManager, indexManager, nodePartitioningManager, pageSinkManager, null, expressionCompiler, pageFunctionCompiler, joinFilterFunctionCompiler, new IndexJoinLookupStats(), this.taskManagerConfig, spillerFactory, singleStreamSpillerFactory, partitioningSpillerFactory, new PagesIndex.TestingFactory(false), joinCompiler, operatorFactories, new OrderingCompiler(plannerContext.getTypeOperators()), new DynamicFilterConfig(), blockTypeOperators, tableExecuteContextManager, exchangeManagerRegistry);
    // plan query
    StageExecutionDescriptor stageExecutionDescriptor = subplan.getFragment().getStageExecutionDescriptor();
    LocalExecutionPlan localExecutionPlan = executionPlanner.plan(taskContext, stageExecutionDescriptor, subplan.getFragment().getRoot(), subplan.getFragment().getPartitioningScheme().getOutputLayout(), plan.getTypes(), subplan.getFragment().getPartitionedSources(), outputFactory);
    // generate splitAssignments
    List<SplitAssignment> splitAssignments = new ArrayList<>();
    long sequenceId = 0;
    for (TableScanNode tableScan : findTableScanNodes(subplan.getFragment().getRoot())) {
        TableHandle table = tableScan.getTable();
        SplitSource splitSource = splitManager.getSplits(session, table, stageExecutionDescriptor.isScanGroupedExecution(tableScan.getId()) ? GROUPED_SCHEDULING : UNGROUPED_SCHEDULING, EMPTY, alwaysTrue());
        ImmutableSet.Builder<ScheduledSplit> scheduledSplits = ImmutableSet.builder();
        while (!splitSource.isFinished()) {
            for (Split split : getNextBatch(splitSource)) {
                scheduledSplits.add(new ScheduledSplit(sequenceId++, tableScan.getId(), split));
            }
        }
        splitAssignments.add(new SplitAssignment(tableScan.getId(), scheduledSplits.build(), true));
    }
    // create drivers
    List<Driver> drivers = new ArrayList<>();
    Map<PlanNodeId, DriverFactory> driverFactoriesBySource = new HashMap<>();
    for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
        for (int i = 0; i < driverFactory.getDriverInstances().orElse(1); i++) {
            if (driverFactory.getSourceId().isPresent()) {
                checkState(driverFactoriesBySource.put(driverFactory.getSourceId().get(), driverFactory) == null);
            } else {
                DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver(), false).addDriverContext();
                Driver driver = driverFactory.createDriver(driverContext);
                drivers.add(driver);
            }
        }
    }
    // add split assignments to the drivers
    ImmutableSet<PlanNodeId> partitionedSources = ImmutableSet.copyOf(subplan.getFragment().getPartitionedSources());
    for (SplitAssignment splitAssignment : splitAssignments) {
        DriverFactory driverFactory = driverFactoriesBySource.get(splitAssignment.getPlanNodeId());
        checkState(driverFactory != null);
        boolean partitioned = partitionedSources.contains(driverFactory.getSourceId().get());
        for (ScheduledSplit split : splitAssignment.getSplits()) {
            DriverContext driverContext = taskContext.addPipelineContext(driverFactory.getPipelineId(), driverFactory.isInputDriver(), driverFactory.isOutputDriver(), partitioned).addDriverContext();
            Driver driver = driverFactory.createDriver(driverContext);
            driver.updateSplitAssignment(new SplitAssignment(split.getPlanNodeId(), ImmutableSet.of(split), true));
            drivers.add(driver);
        }
    }
    for (DriverFactory driverFactory : localExecutionPlan.getDriverFactories()) {
        driverFactory.noMoreDrivers();
    }
    return ImmutableList.copyOf(drivers);
}
Also used : DriverContext(io.trino.operator.DriverContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Driver(io.trino.operator.Driver) SplitAssignment(io.trino.execution.SplitAssignment) PagesIndex(io.trino.operator.PagesIndex) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) ImmutableSet(com.google.common.collect.ImmutableSet) TableExecuteContextManager(io.trino.execution.TableExecuteContextManager) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) DriverFactory(io.trino.operator.DriverFactory) ScheduledSplit(io.trino.execution.ScheduledSplit) LocalExecutionPlanner(io.trino.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(io.trino.operator.index.IndexJoinLookupStats) StageExecutionDescriptor(io.trino.operator.StageExecutionDescriptor) TypeAnalyzer(io.trino.sql.planner.TypeAnalyzer) LocalExecutionPlan(io.trino.sql.planner.LocalExecutionPlanner.LocalExecutionPlan) TableScanNode(io.trino.sql.planner.plan.TableScanNode) TableHandle(io.trino.metadata.TableHandle) SplitSource(io.trino.split.SplitSource) Split(io.trino.metadata.Split) ScheduledSplit(io.trino.execution.ScheduledSplit) SubPlan(io.trino.sql.planner.SubPlan) DynamicFilterConfig(io.trino.execution.DynamicFilterConfig)

Example 23 with DriverContext

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

the class TestHashJoinOperator method testUnwrapsLazyBlocks.

@Test
public void testUnwrapsLazyBlocks() {
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    InternalJoinFilterFunction filterFunction = new TestInternalJoinFilterFunction(((leftPosition, leftPage, rightPosition, rightPage) -> {
        // force loading of probe block
        rightPage.getBlock(1).getLoadedBlock();
        return true;
    }));
    RowPagesBuilder buildPages = rowPagesBuilder(false, Ints.asList(0), ImmutableList.of(BIGINT)).addSequencePage(1, 0);
    BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, true, taskContext, buildPages, Optional.of(filterFunction), false, SINGLE_STREAM_SPILLER_FACTORY);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager();
    RowPagesBuilder probePages = rowPagesBuilder(false, Ints.asList(0), ImmutableList.of(BIGINT, BIGINT));
    List<Page> probeInput = probePages.addSequencePage(1, 0, 0).build();
    probeInput = probeInput.stream().map(page -> new Page(page.getBlock(0), new LazyBlock(1, () -> page.getBlock(1)))).collect(toImmutableList());
    OperatorFactory joinOperatorFactory = operatorFactories.innerJoin(0, new PlanNodeId("test"), lookupSourceFactory, false, false, true, probePages.getTypes(), Ints.asList(0), getHashChannelAsInt(probePages), Optional.empty(), OptionalInt.of(1), PARTITIONING_SPILLER_FACTORY, TYPE_OPERATOR_FACTORY);
    instantiateBuildDrivers(buildSideSetup, taskContext);
    buildLookupSource(executor, buildSideSetup);
    Operator operator = joinOperatorFactory.createOperator(driverContext);
    assertTrue(operator.needsInput());
    operator.addInput(probeInput.get(0));
    operator.finish();
    Page output = operator.getOutput();
    assertFalse(output.getBlock(1) instanceof LazyBlock);
}
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) 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) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) RowPagesBuilder(io.trino.RowPagesBuilder) Page(io.trino.spi.Page) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) LazyBlock(io.trino.spi.block.LazyBlock) 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) Test(org.testng.annotations.Test)

Example 24 with DriverContext

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

the class TestHashJoinOperator 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;
    }));
    // build with 40 entries
    int entries = 40;
    RowPagesBuilder buildPages = rowPagesBuilder(true, Ints.asList(0), ImmutableList.of(BIGINT)).addSequencePage(entries, 42);
    BuildSideSetup buildSideSetup = setupBuildSide(nodePartitioningManager, true, taskContext, buildPages, Optional.of(filterFunction), false, SINGLE_STREAM_SPILLER_FACTORY);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = buildSideSetup.getLookupSourceFactoryManager();
    // probe matching the above 40 entries
    RowPagesBuilder probePages = rowPagesBuilder(false, Ints.asList(0), ImmutableList.of(BIGINT));
    List<Page> probeInput = probePages.addSequencePage(100, 0).build();
    OperatorFactory joinOperatorFactory = operatorFactories.innerJoin(0, new PlanNodeId("test"), lookupSourceFactory, false, false, true, probePages.getTypes(), Ints.asList(0), getHashChannelAsInt(probePages), Optional.empty(), OptionalInt.of(1), PARTITIONING_SPILLER_FACTORY, TYPE_OPERATOR_FACTORY);
    instantiateBuildDrivers(buildSideSetup, taskContext);
    buildLookupSource(executor, buildSideSetup);
    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 < entries; i++) {
        driverContext.getYieldSignal().setWithDelay(5 * SECONDS.toNanos(1), driverContext.getYieldExecutor());
        filterFunctionCalls.set(0);
        assertNull(operator.getOutput());
        assertEquals(filterFunctionCalls.get(), 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());
    // expect output page to be produced within few calls to getOutput(), e.g. to facilitate spill
    Page output = null;
    for (int i = 0; output == null && i < 5; i++) {
        output = operator.getOutput();
    }
    assertNotNull(output);
    driverContext.getYieldSignal().reset();
    // make sure we have all 4 entries
    assertEquals(output.getPositionCount(), entries);
}
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) 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) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) RowPagesBuilder(io.trino.RowPagesBuilder) Page(io.trino.spi.Page) TestInternalJoinFilterFunction(io.trino.operator.join.JoinTestUtils.TestInternalJoinFilterFunction) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Test(org.testng.annotations.Test)

Example 25 with DriverContext

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

the class JoinTestUtils method setupBuildSide.

public static BuildSideSetup setupBuildSide(NodePartitioningManager nodePartitioningManager, boolean parallelBuild, TaskContext taskContext, RowPagesBuilder buildPages, Optional<InternalJoinFilterFunction> filterFunction, boolean spillEnabled, SingleStreamSpillerFactory singleStreamSpillerFactory) {
    Optional<JoinFilterFunctionCompiler.JoinFilterFunctionFactory> filterFunctionFactory = filterFunction.map(function -> (session, addresses, pages) -> new StandardJoinFilterFunction(function, addresses, pages));
    int partitionCount = parallelBuild ? PARTITION_COUNT : 1;
    List<Integer> hashChannels = buildPages.getHashChannels().orElseThrow();
    LocalExchange.LocalExchangeFactory localExchangeFactory = new LocalExchange.LocalExchangeFactory(nodePartitioningManager, taskContext.getSession(), FIXED_HASH_DISTRIBUTION, partitionCount, buildPages.getTypes(), hashChannels, buildPages.getHashChannel(), UNGROUPED_EXECUTION, DataSize.of(32, DataSize.Unit.MEGABYTE), TYPE_OPERATOR_FACTORY);
    LocalExchange.LocalExchangeSinkFactoryId localExchangeSinkFactoryId = localExchangeFactory.newSinkFactoryId();
    localExchangeFactory.noMoreSinkFactories();
    // collect input data into the partitioned exchange
    DriverContext collectDriverContext = taskContext.addPipelineContext(0, true, true, false).addDriverContext();
    ValuesOperator.ValuesOperatorFactory valuesOperatorFactory = new ValuesOperator.ValuesOperatorFactory(0, new PlanNodeId("values"), buildPages.build());
    LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory sinkOperatorFactory = new LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory(localExchangeFactory, 1, new PlanNodeId("sink"), localExchangeSinkFactoryId, Function.identity());
    Driver sourceDriver = Driver.createDriver(collectDriverContext, valuesOperatorFactory.createOperator(collectDriverContext), sinkOperatorFactory.createOperator(collectDriverContext));
    valuesOperatorFactory.noMoreOperators();
    sinkOperatorFactory.noMoreOperators();
    while (!sourceDriver.isFinished()) {
        sourceDriver.process();
    }
    // build side operator factories
    LocalExchangeSourceOperatorFactory sourceOperatorFactory = new LocalExchangeSourceOperatorFactory(0, new PlanNodeId("source"), localExchangeFactory);
    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactoryManager = JoinBridgeManager.lookupAllAtOnce(new PartitionedLookupSourceFactory(buildPages.getTypes(), rangeList(buildPages.getTypes().size()).stream().map(buildPages.getTypes()::get).collect(toImmutableList()), hashChannels.stream().map(buildPages.getTypes()::get).collect(toImmutableList()), partitionCount, false, TYPE_OPERATOR_FACTORY));
    HashBuilderOperatorFactory buildOperatorFactory = new HashBuilderOperatorFactory(1, new PlanNodeId("build"), lookupSourceFactoryManager, rangeList(buildPages.getTypes().size()), hashChannels, buildPages.getHashChannel().map(OptionalInt::of).orElse(OptionalInt.empty()), filterFunctionFactory, Optional.empty(), ImmutableList.of(), 100, new PagesIndex.TestingFactory(false), spillEnabled, singleStreamSpillerFactory, incrementalLoadFactorHashArraySizeSupplier(taskContext.getSession()));
    return new BuildSideSetup(lookupSourceFactoryManager, buildOperatorFactory, sourceOperatorFactory, partitionCount);
}
Also used : DriverContext(io.trino.operator.DriverContext) Driver(io.trino.operator.Driver) HashBuilderOperatorFactory(io.trino.operator.join.HashBuilderOperator.HashBuilderOperatorFactory) LocalExchange(io.trino.operator.exchange.LocalExchange) PagesIndex(io.trino.operator.PagesIndex) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) LocalExchangeSourceOperatorFactory(io.trino.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory) LocalExchangeSinkOperator(io.trino.operator.exchange.LocalExchangeSinkOperator) ValuesOperator(io.trino.operator.ValuesOperator) OptionalInt(java.util.OptionalInt)

Aggregations

DriverContext (io.trino.operator.DriverContext)29 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)19 TaskContext (io.trino.operator.TaskContext)17 Test (org.testng.annotations.Test)17 TestingTaskContext (io.trino.testing.TestingTaskContext)14 OperatorFactory (io.trino.operator.OperatorFactory)13 Page (io.trino.spi.Page)13 Driver (io.trino.operator.Driver)11 RowPagesBuilder (io.trino.RowPagesBuilder)10 Operator (io.trino.operator.Operator)10 MaterializedResult (io.trino.testing.MaterializedResult)8 OperatorContext (io.trino.operator.OperatorContext)7 Type (io.trino.spi.type.Type)7 ImmutableList (com.google.common.collect.ImmutableList)6 ValuesOperatorFactory (io.trino.operator.ValuesOperator.ValuesOperatorFactory)6 WorkProcessorOperator (io.trino.operator.WorkProcessorOperator)6 WorkProcessorOperatorFactory (io.trino.operator.WorkProcessorOperatorFactory)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 PipelineContext (io.trino.operator.PipelineContext)5 PageBufferOperatorFactory (io.trino.operator.index.PageBufferOperator.PageBufferOperatorFactory)5