Search in sources :

Example 11 with PlanFragmentId

use of com.facebook.presto.sql.planner.plan.PlanFragmentId 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)

Example 12 with PlanFragmentId

use of com.facebook.presto.sql.planner.plan.PlanFragmentId 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());
    Visitor visitor = new Visitor(fragments);
    rootFragments.forEach(fragment -> visitor.processFragment(fragment.getId()));
    return visitor.getSchedulerOrder();
}
Also used : SpatialJoinNode(com.facebook.presto.sql.planner.plan.SpatialJoinNode) UnionNode(com.facebook.presto.spi.plan.UnionNode) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) SCHEDULED(com.facebook.presto.execution.StageExecutionState.SCHEDULED) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) IndexJoinNode(com.facebook.presto.sql.planner.plan.IndexJoinNode) InternalPlanVisitor(com.facebook.presto.sql.planner.plan.InternalPlanVisitor) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) StageExecutionState(com.facebook.presto.execution.StageExecutionState) LinkedHashSet(java.util.LinkedHashSet) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) RUNNING(com.facebook.presto.execution.StageExecutionState.RUNNING) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Ordering(com.google.common.collect.Ordering) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) Function.identity(java.util.function.Function.identity) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) InternalPlanVisitor(com.facebook.presto.sql.planner.plan.InternalPlanVisitor) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 13 with PlanFragmentId

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

the class MockRemoteTaskFactory method createTableScanTask.

public MockRemoteTask createTableScanTask(TaskId taskId, InternalNode newNode, List<Split> splits, NodeTaskMap.NodeStatsTracker nodeStatsTracker) {
    VariableReferenceExpression variable = new VariableReferenceExpression(Optional.empty(), "column", VARCHAR);
    PlanNodeId sourceId = new PlanNodeId("sourceId");
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId(0), new TableScanNode(Optional.empty(), sourceId, new TableHandle(new ConnectorId("test"), new TestingTableHandle(), TestingTransactionHandle.create(), Optional.of(TestingHandle.INSTANCE)), ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), TupleDomain.all()), ImmutableSet.of(variable), SOURCE_DISTRIBUTION, ImmutableList.of(sourceId), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(variable)), StageExecutionDescriptor.ungroupedExecution(), false, StatsAndCosts.empty(), Optional.empty());
    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    for (Split sourceSplit : splits) {
        initialSplits.put(sourceId, sourceSplit);
    }
    return createRemoteTask(TEST_SESSION, taskId, newNode, testFragment, initialSplits.build(), createInitialEmptyOutputBuffers(BROADCAST), nodeStatsTracker, true, new TableWriteInfo(Optional.empty(), Optional.empty(), Optional.empty()));
}
Also used : TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) TestingColumnHandle(com.facebook.presto.testing.TestingMetadata.TestingColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TableHandle(com.facebook.presto.spi.TableHandle) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Split(com.facebook.presto.metadata.Split) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 14 with PlanFragmentId

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

the class SectionExecutionFactory method createStreamingLinkedStageExecutions.

/**
 * returns a List of StageExecutionAndSchedulers in a postorder representation of the tree
 */
private List<StageExecutionAndScheduler> createStreamingLinkedStageExecutions(Session session, ExchangeLocationsConsumer parent, StreamingSubPlan plan, Function<PartitioningHandle, NodePartitionMap> partitioningCache, TableWriteInfo tableWriteInfo, Optional<SqlStageExecution> parentStageExecution, boolean summarizeTaskInfo, RemoteTaskFactory remoteTaskFactory, SplitSourceFactory splitSourceFactory, int attemptId) {
    ImmutableList.Builder<StageExecutionAndScheduler> stageExecutionAndSchedulers = ImmutableList.builder();
    PlanFragmentId fragmentId = plan.getFragment().getId();
    StageId stageId = new StageId(session.getQueryId(), fragmentId.getId());
    SqlStageExecution stageExecution = createSqlStageExecution(new StageExecutionId(stageId, attemptId), plan.getFragment(), remoteTaskFactory, session, summarizeTaskInfo, nodeTaskMap, executor, failureDetector, schedulerStats, tableWriteInfo);
    PartitioningHandle partitioningHandle = plan.getFragment().getPartitioning();
    List<RemoteSourceNode> remoteSourceNodes = plan.getFragment().getRemoteSourceNodes();
    Optional<int[]> bucketToPartition = getBucketToPartition(partitioningHandle, partitioningCache, plan.getFragment().getRoot(), remoteSourceNodes);
    // create child stages
    ImmutableSet.Builder<SqlStageExecution> childStagesBuilder = ImmutableSet.builder();
    for (StreamingSubPlan stagePlan : plan.getChildren()) {
        List<StageExecutionAndScheduler> subTree = createStreamingLinkedStageExecutions(session, stageExecution::addExchangeLocations, stagePlan.withBucketToPartition(bucketToPartition), partitioningCache, tableWriteInfo, Optional.of(stageExecution), summarizeTaskInfo, remoteTaskFactory, splitSourceFactory, attemptId);
        stageExecutionAndSchedulers.addAll(subTree);
        childStagesBuilder.add(getLast(subTree).getStageExecution());
    }
    Set<SqlStageExecution> childStageExecutions = childStagesBuilder.build();
    stageExecution.addStateChangeListener(newState -> {
        if (newState.isDone()) {
            childStageExecutions.forEach(SqlStageExecution::cancel);
        }
    });
    StageLinkage stageLinkage = new StageLinkage(fragmentId, parent, childStageExecutions);
    StageScheduler stageScheduler = createStageScheduler(splitSourceFactory, session, plan, partitioningCache, parentStageExecution, stageId, stageExecution, partitioningHandle, tableWriteInfo, childStageExecutions);
    stageExecutionAndSchedulers.add(new StageExecutionAndScheduler(stageExecution, stageLinkage, stageScheduler));
    return stageExecutionAndSchedulers.build();
}
Also used : ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) StageId(com.facebook.presto.execution.StageId) SqlStageExecution(com.facebook.presto.execution.SqlStageExecution) SqlStageExecution.createSqlStageExecution(com.facebook.presto.execution.SqlStageExecution.createSqlStageExecution) StageExecutionId(com.facebook.presto.execution.StageExecutionId) SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler(com.facebook.presto.execution.scheduler.SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) ImmutableSet(com.google.common.collect.ImmutableSet) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PartitioningHandle(com.facebook.presto.sql.planner.PartitioningHandle)

Example 15 with PlanFragmentId

use of com.facebook.presto.sql.planner.plan.PlanFragmentId 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) InternalPlanVisitor(com.facebook.presto.sql.planner.plan.InternalPlanVisitor) 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)

Aggregations

PlanFragmentId (com.facebook.presto.sql.planner.plan.PlanFragmentId)18 PlanFragment (com.facebook.presto.sql.planner.PlanFragment)13 RemoteSourceNode (com.facebook.presto.sql.planner.plan.RemoteSourceNode)7 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)5 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)5 PartitioningScheme (com.facebook.presto.sql.planner.PartitioningScheme)5 ImmutableList (com.google.common.collect.ImmutableList)5 StageExecutionId (com.facebook.presto.execution.StageExecutionId)3 StageId (com.facebook.presto.execution.StageId)3 PrestoSparkTaskDescriptor (com.facebook.presto.spark.PrestoSparkTaskDescriptor)3 SerializedPrestoSparkTaskDescriptor (com.facebook.presto.spark.classloader_interface.SerializedPrestoSparkTaskDescriptor)3 SerializedTaskInfo (com.facebook.presto.spark.classloader_interface.SerializedTaskInfo)3 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Tuple2 (scala.Tuple2)3 Session (com.facebook.presto.Session)2 SqlStageExecution (com.facebook.presto.execution.SqlStageExecution)2 TaskSource (com.facebook.presto.execution.TaskSource)2 MutablePartitionId (com.facebook.presto.spark.classloader_interface.MutablePartitionId)2 PrestoSparkMutableRow (com.facebook.presto.spark.classloader_interface.PrestoSparkMutableRow)2