Search in sources :

Example 11 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class AllAtOnceExecutionSchedule method getPreferredScheduleOrder.

@VisibleForTesting
static List<PlanFragmentId> getPreferredScheduleOrder(Collection<PlanFragment> fragments) {
    // determine output fragment
    Set<PlanFragmentId> remoteSources = fragments.stream().map(PlanFragment::getRemoteSourceNodes).flatMap(Collection::stream).map(RemoteSourceNode::getSourceFragmentIds).flatMap(Collection::stream).collect(toImmutableSet());
    Set<PlanFragment> rootFragments = fragments.stream().filter(fragment -> !remoteSources.contains(fragment.getId())).collect(toImmutableSet());
    checkArgument(rootFragments.size() == 1, "Expected one root fragment, but found: " + rootFragments);
    Visitor visitor = new Visitor(fragments);
    visitor.processFragment(getOnlyElement(rootFragments).getId());
    return visitor.getSchedulerOrder();
}
Also used : SCHEDULED(com.facebook.presto.execution.StageState.SCHEDULED) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) RUNNING(com.facebook.presto.execution.StageState.RUNNING) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) PlanVisitor(com.facebook.presto.sql.planner.plan.PlanVisitor) ImmutableList(com.google.common.collect.ImmutableList) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) IndexJoinNode(com.facebook.presto.sql.planner.plan.IndexJoinNode) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) LinkedHashSet(java.util.LinkedHashSet) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) ImmutableCollectors.toImmutableMap(com.facebook.presto.util.ImmutableCollectors.toImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) Collection(java.util.Collection) Set(java.util.Set) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) StageState(com.facebook.presto.execution.StageState) List(java.util.List) UnionNode(com.facebook.presto.sql.planner.plan.UnionNode) Ordering(com.google.common.collect.Ordering) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) PlanVisitor(com.facebook.presto.sql.planner.plan.PlanVisitor) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 12 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class PhasedExecutionSchedule method extractPhases.

@VisibleForTesting
static List<Set<PlanFragmentId>> extractPhases(Collection<PlanFragment> fragments) {
    // Build a graph where the plan fragments are vertexes and the edges represent
    // a before -> after relationship.  For example, a join hash build has an edge
    // to the join probe.
    DirectedGraph<PlanFragmentId, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
    fragments.forEach(fragment -> graph.addVertex(fragment.getId()));
    Visitor visitor = new Visitor(fragments, graph);
    for (PlanFragment fragment : fragments) {
        visitor.processFragment(fragment.getId());
    }
    // Computes all the strongly connected components of the directed graph.
    // These are the "phases" which hold the set of fragments that must be started
    // at the same time to avoid deadlock.
    List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(graph).stronglyConnectedSets();
    Map<PlanFragmentId, Set<PlanFragmentId>> componentMembership = new HashMap<>();
    for (Set<PlanFragmentId> component : components) {
        for (PlanFragmentId planFragmentId : component) {
            componentMembership.put(planFragmentId, component);
        }
    }
    // build graph of components (phases)
    DirectedGraph<Set<PlanFragmentId>, DefaultEdge> componentGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
    components.forEach(componentGraph::addVertex);
    for (DefaultEdge edge : graph.edgeSet()) {
        PlanFragmentId source = graph.getEdgeSource(edge);
        PlanFragmentId target = graph.getEdgeTarget(edge);
        Set<PlanFragmentId> from = componentMembership.get(source);
        Set<PlanFragmentId> to = componentMembership.get(target);
        if (!from.equals(to)) {
            // the topological order iterator below doesn't include vertices that have self-edges, so don't add them
            componentGraph.addEdge(from, to);
        }
    }
    List<Set<PlanFragmentId>> schedulePhases = ImmutableList.copyOf(new TopologicalOrderIterator<>(componentGraph));
    return schedulePhases;
}
Also used : HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PlanVisitor(com.facebook.presto.sql.planner.plan.PlanVisitor) DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) HashMap(java.util.HashMap) DefaultEdge(org.jgrapht.graph.DefaultEdge) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class TestSourcePartitionedScheduler method createPlan.

private static StageExecutionPlan createPlan(ConnectorSplitSource splitSource) {
    Symbol symbol = new Symbol("column");
    // table scan with splitCount splits
    PlanNodeId tableScanNodeId = new PlanNodeId("plan_id");
    TableScanNode tableScan = new TableScanNode(tableScanNodeId, new TableHandle(CONNECTOR_ID, new TestingTableHandle()), ImmutableList.of(symbol), ImmutableMap.of(symbol, new TestingColumnHandle("column")), Optional.empty(), TupleDomain.all(), null);
    RemoteSourceNode remote = new RemoteSourceNode(new PlanNodeId("remote_id"), new PlanFragmentId("plan_fragment_id"), ImmutableList.of());
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId("plan_id"), new JoinNode(new PlanNodeId("join_id"), INNER, tableScan, remote, ImmutableList.of(), ImmutableList.<Symbol>builder().addAll(tableScan.getOutputSymbols()).addAll(remote.getOutputSymbols()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(JoinNode.DistributionType.PARTITIONED)), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(tableScanNodeId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)));
    return new StageExecutionPlan(testFragment, ImmutableMap.of(tableScanNodeId, new ConnectorAwareSplitSource(CONNECTOR_ID, TestingTransactionHandle.create(), splitSource)), ImmutableList.of());
}
Also used : Symbol(com.facebook.presto.sql.planner.Symbol) TestingTableHandle(com.facebook.presto.sql.planner.TestingTableHandle) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) StageExecutionPlan(com.facebook.presto.sql.planner.StageExecutionPlan) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) ConnectorAwareSplitSource(com.facebook.presto.split.ConnectorAwareSplitSource) PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) TestingColumnHandle(com.facebook.presto.sql.planner.TestingColumnHandle) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode) TestingTableHandle(com.facebook.presto.sql.planner.TestingTableHandle) TableHandle(com.facebook.presto.metadata.TableHandle) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId)

Example 14 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class TestPhasedExecutionSchedule method testJoinWithDeepSources.

@Test
public void testJoinWithDeepSources() throws Exception {
    PlanFragment buildSourceFragment = createTableScanPlanFragment("buildSource");
    PlanFragment buildMiddleFragment = createExchangePlanFragment("buildMiddle", buildSourceFragment);
    PlanFragment buildTopFragment = createExchangePlanFragment("buildTop", buildMiddleFragment);
    PlanFragment probeSourceFragment = createTableScanPlanFragment("probeSource");
    PlanFragment probeMiddleFragment = createExchangePlanFragment("probeMiddle", probeSourceFragment);
    PlanFragment probeTopFragment = createExchangePlanFragment("probeTop", probeMiddleFragment);
    PlanFragment joinFragment = createJoinPlanFragment(INNER, "join", buildTopFragment, probeTopFragment);
    List<Set<PlanFragmentId>> phases = PhasedExecutionSchedule.extractPhases(ImmutableList.of(joinFragment, buildTopFragment, buildMiddleFragment, buildSourceFragment, probeTopFragment, probeMiddleFragment, probeSourceFragment));
    assertEquals(phases, ImmutableList.of(ImmutableSet.of(joinFragment.getId()), ImmutableSet.of(buildTopFragment.getId()), ImmutableSet.of(buildMiddleFragment.getId()), ImmutableSet.of(buildSourceFragment.getId()), ImmutableSet.of(probeTopFragment.getId()), ImmutableSet.of(probeMiddleFragment.getId()), ImmutableSet.of(probeSourceFragment.getId())));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) Test(org.testng.annotations.Test)

Example 15 with PlanFragment

use of com.facebook.presto.sql.planner.PlanFragment in project presto by prestodb.

the class TestStageStateMachine method createValuesPlan.

private static PlanFragment createValuesPlan() {
    Symbol symbol = new Symbol("column");
    PlanNodeId valuesNodeId = new PlanNodeId("plan");
    PlanFragment planFragment = new PlanFragment(new PlanFragmentId("plan"), new ValuesNode(valuesNodeId, ImmutableList.of(symbol), ImmutableList.of(ImmutableList.of(new StringLiteral("foo")))), ImmutableMap.of(symbol, VARCHAR), SOURCE_DISTRIBUTION, ImmutableList.of(valuesNodeId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(symbol)));
    return planFragment;
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) Symbol(com.facebook.presto.sql.planner.Symbol) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PlanFragment(com.facebook.presto.sql.planner.PlanFragment)

Aggregations

PlanFragment (com.facebook.presto.sql.planner.PlanFragment)15 ImmutableSet (com.google.common.collect.ImmutableSet)8 Set (java.util.Set)8 PlanFragmentId (com.facebook.presto.sql.planner.plan.PlanFragmentId)6 Test (org.testng.annotations.Test)5 PartitioningScheme (com.facebook.presto.sql.planner.PartitioningScheme)3 Symbol (com.facebook.presto.sql.planner.Symbol)3 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)3 TableHandle (com.facebook.presto.metadata.TableHandle)2 TestingColumnHandle (com.facebook.presto.sql.planner.TestingColumnHandle)2 TestingTableHandle (com.facebook.presto.sql.planner.TestingTableHandle)2 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)2 PlanVisitor (com.facebook.presto.sql.planner.plan.PlanVisitor)2 RemoteSourceNode (com.facebook.presto.sql.planner.plan.RemoteSourceNode)2 TableScanNode (com.facebook.presto.sql.planner.plan.TableScanNode)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 HashSet (java.util.HashSet)2 TaskSource (com.facebook.presto.TaskSource)1 FailureInfo (com.facebook.presto.client.FailureInfo)1