Search in sources :

Example 31 with PlanFragment

use of io.trino.sql.planner.PlanFragment 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 32 with PlanFragment

use of io.trino.sql.planner.PlanFragment in project trino by trinodb.

the class QueryMonitor method extractPlanNodeStats.

private static void extractPlanNodeStats(StageInfo stageInfo, ImmutableMultimap.Builder<FragmentNode, OperatorStats> planNodeStats) {
    PlanFragment fragment = stageInfo.getPlan();
    if (fragment == null) {
        return;
    }
    // Note: a plan node may be mapped to multiple operators
    Map<PlanNodeId, Collection<OperatorStats>> allOperatorStats = Multimaps.index(stageInfo.getStageStats().getOperatorSummaries(), OperatorStats::getPlanNodeId).asMap();
    // Sometimes a plan node is merged with other nodes into a single operator, and in that case,
    // use the stats of the nearest parent node with stats.
    fragment.getRoot().accept(new PlanVisitor<Void, Collection<OperatorStats>>() {

        @Override
        protected Void visitPlan(PlanNode node, Collection<OperatorStats> parentStats) {
            Collection<OperatorStats> operatorStats = allOperatorStats.getOrDefault(node.getId(), parentStats);
            planNodeStats.putAll(new FragmentNode(fragment.getId(), node.getId()), operatorStats);
            for (PlanNode child : node.getSources()) {
                child.accept(this, operatorStats);
            }
            return null;
        }
    }, ImmutableList.of());
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PlanNode(io.trino.sql.planner.plan.PlanNode) Collection(java.util.Collection) OperatorStats(io.trino.operator.OperatorStats) PlanFragment(io.trino.sql.planner.PlanFragment)

Example 33 with PlanFragment

use of io.trino.sql.planner.PlanFragment in project trino by trinodb.

the class StatsAndCosts method reconstructStatsAndCosts.

private static void reconstructStatsAndCosts(StageInfo stage, ImmutableMap.Builder<PlanNodeId, PlanNodeStatsEstimate> planNodeStats, ImmutableMap.Builder<PlanNodeId, PlanCostEstimate> planNodeCosts) {
    PlanFragment planFragment = stage.getPlan();
    if (planFragment != null) {
        planNodeStats.putAll(planFragment.getStatsAndCosts().getStats());
        planNodeCosts.putAll(planFragment.getStatsAndCosts().getCosts());
    }
    for (StageInfo subStage : stage.getSubStages()) {
        reconstructStatsAndCosts(subStage, planNodeStats, planNodeCosts);
    }
}
Also used : StageInfo(io.trino.execution.StageInfo) PlanFragment(io.trino.sql.planner.PlanFragment)

Example 34 with PlanFragment

use of io.trino.sql.planner.PlanFragment in project trino by trinodb.

the class GraphvizPrinter method printSubPlan.

private static void printSubPlan(SubPlan plan, Map<PlanFragmentId, PlanFragment> fragmentsById, PlanNodeIdGenerator idGenerator, StringBuilder output) {
    PlanFragment fragment = plan.getFragment();
    printFragmentNodes(output, fragment, idGenerator);
    fragment.getRoot().accept(new EdgePrinter(output, fragmentsById, idGenerator), null);
    for (SubPlan child : plan.getChildren()) {
        printSubPlan(child, fragmentsById, idGenerator, output);
    }
}
Also used : PlanFragment(io.trino.sql.planner.PlanFragment) SubPlan(io.trino.sql.planner.SubPlan)

Example 35 with PlanFragment

use of io.trino.sql.planner.PlanFragment in project trino by trinodb.

the class TestLegacyPhasedExecutionSchedule method testBroadcastJoin.

@Test
public void testBroadcastJoin() {
    PlanFragment buildFragment = createTableScanPlanFragment("build");
    PlanFragment joinFragment = createBroadcastJoinPlanFragment("join", buildFragment);
    List<Set<PlanFragmentId>> phases = LegacyPhasedExecutionSchedule.extractPhases(ImmutableList.of(joinFragment, buildFragment));
    assertEquals(phases, ImmutableList.of(ImmutableSet.of(joinFragment.getId(), buildFragment.getId())));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PlanFragment(io.trino.sql.planner.PlanFragment) PlanUtils.createExchangePlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createExchangePlanFragment) PlanUtils.createBroadcastJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createBroadcastJoinPlanFragment) PlanUtils.createTableScanPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createTableScanPlanFragment) PlanUtils.createJoinPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createJoinPlanFragment) PlanUtils.createUnionPlanFragment(io.trino.execution.scheduler.policy.PlanUtils.createUnionPlanFragment) Test(org.testng.annotations.Test)

Aggregations

PlanFragment (io.trino.sql.planner.PlanFragment)41 Test (org.testng.annotations.Test)22 PlanFragmentId (io.trino.sql.planner.plan.PlanFragmentId)16 ImmutableSet (com.google.common.collect.ImmutableSet)12 NodeTaskMap (io.trino.execution.NodeTaskMap)11 PipelinedStageExecution.createPipelinedStageExecution (io.trino.execution.scheduler.PipelinedStageExecution.createPipelinedStageExecution)11 SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler (io.trino.execution.scheduler.SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler)11 PlanUtils.createBroadcastJoinPlanFragment (io.trino.execution.scheduler.policy.PlanUtils.createBroadcastJoinPlanFragment)11 PlanUtils.createJoinPlanFragment (io.trino.execution.scheduler.policy.PlanUtils.createJoinPlanFragment)11 PlanUtils.createTableScanPlanFragment (io.trino.execution.scheduler.policy.PlanUtils.createTableScanPlanFragment)11 Set (java.util.Set)11 Symbol (io.trino.sql.planner.Symbol)10 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)10 PartitioningScheme (io.trino.sql.planner.PartitioningScheme)9 MockRemoteTask (io.trino.execution.MockRemoteTaskFactory.MockRemoteTask)8 PartitionedSplitsInfo (io.trino.execution.PartitionedSplitsInfo)8 RemoteTask (io.trino.execution.RemoteTask)8 RemoteSourceNode (io.trino.sql.planner.plan.RemoteSourceNode)8 JoinNode (io.trino.sql.planner.plan.JoinNode)7 Duration (io.airlift.units.Duration)6