Search in sources :

Example 6 with RemoteSourceNode

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

the class SqlStageExecution method addExchangeLocations.

public synchronized void addExchangeLocations(PlanFragmentId fragmentId, Set<RemoteTask> sourceTasks, boolean noMoreExchangeLocations) {
    requireNonNull(fragmentId, "fragmentId is null");
    requireNonNull(sourceTasks, "sourceTasks is null");
    RemoteSourceNode remoteSource = exchangeSources.get(fragmentId);
    checkArgument(remoteSource != null, "Unknown remote source %s. Known sources are %s", fragmentId, exchangeSources.keySet());
    this.sourceTasks.putAll(remoteSource.getId(), sourceTasks);
    for (RemoteTask task : getAllTasks()) {
        ImmutableMultimap.Builder<PlanNodeId, Split> newSplits = ImmutableMultimap.builder();
        for (RemoteTask sourceTask : sourceTasks) {
            TaskStatus sourceTaskStatus = sourceTask.getTaskStatus();
            newSplits.put(remoteSource.getId(), createRemoteSplitFor(task.getTaskId(), sourceTask.getRemoteTaskLocation(), sourceTask.getTaskId()));
        }
        task.addSplits(newSplits.build());
    }
    if (noMoreExchangeLocations) {
        completeSourceFragments.add(fragmentId);
        // is the source now complete?
        if (completeSourceFragments.containsAll(remoteSource.getSourceFragmentIds())) {
            completeSources.add(remoteSource.getId());
            for (RemoteTask task : getAllTasks()) {
                task.noMoreSplits(remoteSource.getId());
            }
        }
    }
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RemoteSplit(com.facebook.presto.split.RemoteSplit) Split(com.facebook.presto.metadata.Split)

Example 7 with RemoteSourceNode

use of com.facebook.presto.sql.planner.plan.RemoteSourceNode 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 8 with RemoteSourceNode

use of com.facebook.presto.sql.planner.plan.RemoteSourceNode 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 9 with RemoteSourceNode

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

the class TestPhasedExecutionSchedule method createJoinPlanFragment.

private static PlanFragment createJoinPlanFragment(JoinNode.Type joinType, String name, PlanFragment buildFragment, PlanFragment probeFragment) {
    RemoteSourceNode probe = new RemoteSourceNode(Optional.empty(), new PlanNodeId("probe_id"), probeFragment.getId(), ImmutableList.of(), false, Optional.empty(), REPARTITION);
    RemoteSourceNode build = new RemoteSourceNode(Optional.empty(), new PlanNodeId("build_id"), buildFragment.getId(), ImmutableList.of(), false, Optional.empty(), REPARTITION);
    PlanNode planNode = new JoinNode(Optional.empty(), new PlanNodeId(name + "_id"), joinType, probe, build, ImmutableList.of(), ImmutableList.<VariableReferenceExpression>builder().addAll(probe.getOutputVariables()).addAll(build.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of());
    return createFragment(planNode);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression)

Example 10 with RemoteSourceNode

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

the class TestSourcePartitionedScheduler method createPlan.

private static SubPlan createPlan() {
    VariableReferenceExpression variable = new VariableReferenceExpression(Optional.empty(), "column", VARCHAR);
    // table scan with splitCount splits
    TableScanNode tableScan = new TableScanNode(Optional.empty(), TABLE_SCAN_NODE_ID, new TableHandle(CONNECTOR_ID, new TestingTableHandle(), TestingTransactionHandle.create(), Optional.empty()), ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), TupleDomain.all());
    RemoteSourceNode remote = new RemoteSourceNode(Optional.empty(), new PlanNodeId("remote_id"), new PlanFragmentId(0), ImmutableList.of(), false, Optional.empty(), GATHER);
    PlanFragment testFragment = new PlanFragment(new PlanFragmentId(0), new JoinNode(Optional.empty(), new PlanNodeId("join_id"), INNER, tableScan, remote, ImmutableList.of(), ImmutableList.<VariableReferenceExpression>builder().addAll(tableScan.getOutputVariables()).addAll(remote.getOutputVariables()).build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()), ImmutableSet.of(variable), SOURCE_DISTRIBUTION, ImmutableList.of(TABLE_SCAN_NODE_ID), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), ImmutableList.of(variable)), StageExecutionDescriptor.ungroupedExecution(), false, StatsAndCosts.empty(), Optional.empty());
    return new SubPlan(testFragment, ImmutableList.of());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) TestingColumnHandle(com.facebook.presto.testing.TestingMetadata.TestingColumnHandle) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) TableHandle(com.facebook.presto.spi.TableHandle) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) SubPlan(com.facebook.presto.sql.planner.SubPlan)

Aggregations

RemoteSourceNode (com.facebook.presto.sql.planner.plan.RemoteSourceNode)11 PlanFragmentId (com.facebook.presto.sql.planner.plan.PlanFragmentId)6 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)5 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)5 PlanFragment (com.facebook.presto.sql.planner.PlanFragment)4 ImmutableList (com.google.common.collect.ImmutableList)4 PlanNode (com.facebook.presto.spi.plan.PlanNode)3 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)3 SqlStageExecution (com.facebook.presto.execution.SqlStageExecution)2 StageExecutionId (com.facebook.presto.execution.StageExecutionId)2 StageId (com.facebook.presto.execution.StageId)2 Split (com.facebook.presto.metadata.Split)2 TableHandle (com.facebook.presto.spi.TableHandle)2 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)2 RemoteSplit (com.facebook.presto.split.RemoteSplit)2 PartitioningHandle (com.facebook.presto.sql.planner.PartitioningHandle)2 PartitioningScheme (com.facebook.presto.sql.planner.PartitioningScheme)2 SubPlan (com.facebook.presto.sql.planner.SubPlan)2 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2