Search in sources :

Example 16 with PlanFragmentId

use of io.trino.sql.planner.plan.PlanFragmentId in project trino by trinodb.

the class TestDynamicFilterService method createPlan.

private static PlanFragment createPlan(DynamicFilterId consumedDynamicFilterId, DynamicFilterId producedDynamicFilterId, PartitioningHandle stagePartitioning, ExchangeNode.Type exchangeType) {
    Symbol symbol = new Symbol("column");
    Symbol buildSymbol = new Symbol("buildColumn");
    PlanNodeId tableScanNodeId = new PlanNodeId("plan_id");
    TableScanNode tableScan = TableScanNode.newInstance(tableScanNodeId, TEST_TABLE_HANDLE, ImmutableList.of(symbol), ImmutableMap.of(symbol, new TestingMetadata.TestingColumnHandle("column")), false, Optional.empty());
    FilterNode filterNode = new FilterNode(new PlanNodeId("filter_node_id"), tableScan, createDynamicFilterExpression(session, createTestMetadataManager(), consumedDynamicFilterId, VARCHAR, symbol.toSymbolReference()));
    RemoteSourceNode remote = new RemoteSourceNode(new PlanNodeId("remote_id"), new PlanFragmentId("plan_fragment_id"), ImmutableList.of(buildSymbol), Optional.empty(), exchangeType, RetryPolicy.NONE);
    return new PlanFragment(new PlanFragmentId("plan_id"), new JoinNode(new PlanNodeId("join_id"), INNER, filterNode, remote, ImmutableList.of(), tableScan.getOutputSymbols(), remote.getOutputSymbols(), false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(producedDynamicFilterId, buildSymbol), Optional.empty()), ImmutableMap.of(symbol, VARCHAR), stagePartitioning, ImmutableList.of(tableScanNodeId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty());
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) RemoteSourceNode(io.trino.sql.planner.plan.RemoteSourceNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) PartitioningScheme(io.trino.sql.planner.PartitioningScheme) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) PlanFragment(io.trino.sql.planner.PlanFragment)

Example 17 with PlanFragmentId

use of io.trino.sql.planner.plan.PlanFragmentId in project trino by trinodb.

the class TestPhasedExecutionSchedule method testAggregation.

@Test
public void testAggregation() {
    PlanFragment sourceFragment = createTableScanPlanFragment("probe");
    PlanFragment aggregationFragment = createAggregationFragment("aggregation", sourceFragment);
    PlanFragment buildFragment = createTableScanPlanFragment("build");
    PlanFragment joinFragment = createJoinPlanFragment(INNER, REPLICATED, "join", buildFragment, aggregationFragment);
    TestingStageExecution sourceStage = new TestingStageExecution(sourceFragment);
    TestingStageExecution aggregationStage = new TestingStageExecution(aggregationFragment);
    TestingStageExecution buildStage = new TestingStageExecution(buildFragment);
    TestingStageExecution joinStage = new TestingStageExecution(joinFragment);
    PhasedExecutionSchedule schedule = PhasedExecutionSchedule.forStages(ImmutableSet.of(sourceStage, aggregationStage, buildStage, joinStage), dynamicFilterService);
    assertThat(schedule.getSortedFragments()).containsExactly(buildFragment.getId(), sourceFragment.getId(), aggregationFragment.getId(), joinFragment.getId());
    // aggregation and source stage should start immediately, join stage should wait for build stage to complete
    DirectedGraph<PlanFragmentId, FragmentsEdge> dependencies = schedule.getFragmentDependency();
    assertThat(dependencies.edgeSet()).containsExactly(new FragmentsEdge(buildFragment.getId(), joinFragment.getId()));
    assertThat(getActiveFragments(schedule)).containsExactly(buildFragment.getId(), sourceFragment.getId(), aggregationFragment.getId());
}
Also used : FragmentsEdge(io.trino.execution.scheduler.policy.PhasedExecutionSchedule.FragmentsEdge) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) PlanFragment(io.trino.sql.planner.PlanFragment) PlanUtils.createTableScanPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createTableScanPlanFragment) PlanUtils.createJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createJoinPlanFragment) PlanUtils.createBroadcastJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createBroadcastJoinPlanFragment) PlanUtils.createBroadcastAndPartitionedJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createBroadcastAndPartitionedJoinPlanFragment) Test(org.testng.annotations.Test)

Example 18 with PlanFragmentId

use of io.trino.sql.planner.plan.PlanFragmentId in project trino by trinodb.

the class TestPhasedExecutionSchedule method testDependentStageAbortedBeforeStarted.

@Test
public void testDependentStageAbortedBeforeStarted() {
    PlanFragment sourceFragment = createTableScanPlanFragment("probe");
    PlanFragment aggregationFragment = createAggregationFragment("aggregation", sourceFragment);
    PlanFragment buildFragment = createTableScanPlanFragment("build");
    PlanFragment joinFragment = createJoinPlanFragment(INNER, REPLICATED, "join", buildFragment, aggregationFragment);
    TestingStageExecution sourceStage = new TestingStageExecution(sourceFragment);
    TestingStageExecution aggregationStage = new TestingStageExecution(aggregationFragment);
    TestingStageExecution buildStage = new TestingStageExecution(buildFragment);
    TestingStageExecution joinStage = new TestingStageExecution(joinFragment);
    PhasedExecutionSchedule schedule = PhasedExecutionSchedule.forStages(ImmutableSet.of(sourceStage, aggregationStage, buildStage, joinStage), dynamicFilterService);
    assertThat(schedule.getSortedFragments()).containsExactly(buildFragment.getId(), sourceFragment.getId(), aggregationFragment.getId(), joinFragment.getId());
    // aggregation and source stage should start immediately, join stage should wait for build stage to complete
    DirectedGraph<PlanFragmentId, FragmentsEdge> dependencies = schedule.getFragmentDependency();
    assertThat(dependencies.edgeSet()).containsExactly(new FragmentsEdge(buildFragment.getId(), joinFragment.getId()));
    assertThat(getActiveFragments(schedule)).containsExactly(buildFragment.getId(), sourceFragment.getId(), aggregationFragment.getId());
    // abort non-active join stage
    joinStage.setState(ABORTED);
    // dependencies finish
    buildStage.setState(FINISHED);
    aggregationStage.setState(FINISHED);
    sourceStage.setState(FINISHED);
    // join stage already aborted. Whole schedule should be marked as finished
    schedule.schedule();
    assertThat(schedule.isFinished()).isTrue();
}
Also used : FragmentsEdge(io.trino.execution.scheduler.policy.PhasedExecutionSchedule.FragmentsEdge) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) PlanFragment(io.trino.sql.planner.PlanFragment) PlanUtils.createTableScanPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createTableScanPlanFragment) PlanUtils.createJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createJoinPlanFragment) PlanUtils.createBroadcastJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createBroadcastJoinPlanFragment) PlanUtils.createBroadcastAndPartitionedJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createBroadcastAndPartitionedJoinPlanFragment) Test(org.testng.annotations.Test)

Example 19 with PlanFragmentId

use of io.trino.sql.planner.plan.PlanFragmentId in project trino by trinodb.

the class TestPhasedExecutionSchedule method testPartitionedJoin.

@Test
public void testPartitionedJoin() {
    PlanFragment buildFragment = createTableScanPlanFragment("build");
    PlanFragment probeFragment = createTableScanPlanFragment("probe");
    PlanFragment joinFragment = createJoinPlanFragment(INNER, PARTITIONED, "join", buildFragment, probeFragment);
    TestingStageExecution buildStage = new TestingStageExecution(buildFragment);
    TestingStageExecution probeStage = new TestingStageExecution(probeFragment);
    TestingStageExecution joinStage = new TestingStageExecution(joinFragment);
    PhasedExecutionSchedule schedule = PhasedExecutionSchedule.forStages(ImmutableSet.of(buildStage, probeStage, joinStage), dynamicFilterService);
    assertThat(schedule.getSortedFragments()).containsExactly(buildFragment.getId(), probeFragment.getId(), joinFragment.getId());
    // single dependency between build and probe stages
    DirectedGraph<PlanFragmentId, FragmentsEdge> dependencies = schedule.getFragmentDependency();
    assertThat(dependencies.edgeSet()).containsExactlyInAnyOrder(new FragmentsEdge(buildFragment.getId(), probeFragment.getId()));
    // build and join stage should start immediately
    assertThat(getActiveFragments(schedule)).containsExactly(buildFragment.getId(), joinFragment.getId());
    // probe stage should start after build stage is completed
    ListenableFuture<Void> rescheduleFuture = schedule.getRescheduleFuture().orElseThrow();
    assertThat(rescheduleFuture).isNotDone();
    buildStage.setState(FLUSHING);
    assertThat(rescheduleFuture).isDone();
    schedule.schedule();
    assertThat(getActiveFragments(schedule)).containsExactly(joinFragment.getId(), probeFragment.getId());
    // make sure scheduler finishes
    rescheduleFuture = schedule.getRescheduleFuture().orElseThrow();
    assertThat(rescheduleFuture).isNotDone();
    probeStage.setState(FINISHED);
    assertThat(rescheduleFuture).isNotDone();
    joinStage.setState(FINISHED);
    schedule.schedule();
    assertThat(getActiveFragments(schedule)).isEmpty();
    assertThat(schedule.isFinished()).isTrue();
}
Also used : FragmentsEdge(io.trino.execution.scheduler.policy.PhasedExecutionSchedule.FragmentsEdge) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId) PlanFragment(io.trino.sql.planner.PlanFragment) PlanUtils.createTableScanPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createTableScanPlanFragment) PlanUtils.createJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createJoinPlanFragment) PlanUtils.createBroadcastJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createBroadcastJoinPlanFragment) PlanUtils.createBroadcastAndPartitionedJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createBroadcastAndPartitionedJoinPlanFragment) Test(org.testng.annotations.Test)

Example 20 with PlanFragmentId

use of io.trino.sql.planner.plan.PlanFragmentId in project trino by trinodb.

the class StageTaskSourceFactory method getInputsForRemoteSources.

private static ListMultimap<PlanNodeId, ExchangeSourceHandle> getInputsForRemoteSources(List<RemoteSourceNode> remoteSources, Multimap<PlanFragmentId, ExchangeSourceHandle> exchangeSourceHandles) {
    ImmutableListMultimap.Builder<PlanNodeId, ExchangeSourceHandle> result = ImmutableListMultimap.builder();
    for (RemoteSourceNode remoteSource : remoteSources) {
        for (PlanFragmentId fragmentId : remoteSource.getSourceFragmentIds()) {
            Collection<ExchangeSourceHandle> handles = requireNonNull(exchangeSourceHandles.get(fragmentId), () -> "exchange source handle is missing for fragment: " + fragmentId);
            if (remoteSource.getExchangeType() == GATHER || remoteSource.getExchangeType() == REPLICATE) {
                checkArgument(handles.size() <= 1, "at most 1 exchange source handle is expected, got: %s", handles);
            }
            result.putAll(remoteSource.getId(), handles);
        }
    }
    return result.build();
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) RemoteSourceNode(io.trino.sql.planner.plan.RemoteSourceNode) ExchangeSourceHandle(io.trino.spi.exchange.ExchangeSourceHandle) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) PlanFragmentId(io.trino.sql.planner.plan.PlanFragmentId)

Aggregations

PlanFragmentId (io.trino.sql.planner.plan.PlanFragmentId)22 PlanFragment (io.trino.sql.planner.PlanFragment)15 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)10 RemoteSourceNode (io.trino.sql.planner.plan.RemoteSourceNode)10 Test (org.testng.annotations.Test)7 PartitioningScheme (io.trino.sql.planner.PartitioningScheme)6 Symbol (io.trino.sql.planner.Symbol)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 FragmentsEdge (io.trino.execution.scheduler.policy.PhasedExecutionSchedule.FragmentsEdge)5 PlanUtils.createBroadcastAndPartitionedJoinPlanFragment (io.trino.execution.scheduler.policy.PlanUtils.createBroadcastAndPartitionedJoinPlanFragment)5 PlanUtils.createBroadcastJoinPlanFragment (io.trino.execution.scheduler.policy.PlanUtils.createBroadcastJoinPlanFragment)5 PlanUtils.createJoinPlanFragment (io.trino.execution.scheduler.policy.PlanUtils.createJoinPlanFragment)5 PlanUtils.createTableScanPlanFragment (io.trino.execution.scheduler.policy.PlanUtils.createTableScanPlanFragment)5 JoinNode (io.trino.sql.planner.plan.JoinNode)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 ExchangeSourceHandle (io.trino.spi.exchange.ExchangeSourceHandle)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3