Search in sources :

Example 1 with PlanFragmentId

use of io.prestosql.sql.planner.plan.PlanFragmentId in project hetu-core by openlookeng.

the class TestUtil method createExchangePlanFragment.

private static PlanFragment createExchangePlanFragment(RowExpression expr) {
    Symbol testSymbol = new Symbol("a");
    Map<Symbol, ColumnHandle> scanAssignments = ImmutableMap.<Symbol, ColumnHandle>builder().put(testSymbol, new TestingMetadata.TestingColumnHandle("a")).build();
    Map<Symbol, ColumnHandle> assignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(testSymbol)));
    TableScanNode tableScanNode = new TableScanNode(new PlanNodeId(UUID.randomUUID().toString()), makeTableHandle(TupleDomain.none()), ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.none(), Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata());
    FilterNode filterNode = planBuilder.filter(expr, tableScanNode);
    PlanNode planNode = new LimitNode(new PlanNodeId("limit"), filterNode, 1, false);
    ImmutableMap.Builder<Symbol, Type> types = ImmutableMap.builder();
    for (Symbol symbol : planNode.getOutputSymbols()) {
        types.put(symbol, VARCHAR);
    }
    return new PlanFragment(new PlanFragmentId("limit_fragment_id"), planNode, types.build(), SOURCE_DISTRIBUTION, ImmutableList.of(planNode.getId()), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), planNode.getOutputSymbols()), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty(), Optional.empty(), Optional.empty());
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Symbol(io.prestosql.spi.plan.Symbol) PartitioningScheme(io.prestosql.sql.planner.PartitioningScheme) FilterNode(io.prestosql.spi.plan.FilterNode) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) PlanFragment(io.prestosql.sql.planner.PlanFragment) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) LimitNode(io.prestosql.spi.plan.LimitNode) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) UUID(java.util.UUID)

Example 2 with PlanFragmentId

use of io.prestosql.sql.planner.plan.PlanFragmentId in project hetu-core by openlookeng.

the class DistributedExecutionPlanner method collectSources.

private List<MarkerSplitSource> collectSources(Map<PlanFragmentId, Object> leftmostSources, Object source) {
    if (source instanceof ValuesNode) {
        // TODO-cp-I2X9J6: should we worry about dependencies about Values operators, when it's the "left" of a join?
        return ImmutableList.of();
    }
    if (source instanceof RemoteSourceNode) {
        List<PlanFragmentId> fragments = ((RemoteSourceNode) source).getSourceFragmentIds();
        if (fragments.size() == 1) {
            return collectSources(leftmostSources, leftmostSources.get(fragments.get(0)));
        }
        List<MarkerSplitSource> sources = new ArrayList<>();
        for (PlanFragmentId id : fragments) {
            sources.addAll(collectSources(leftmostSources, leftmostSources.get(id)));
        }
        // Adding all these sources as "union dependencies" for each other, to make sure they produce the same set of markers.
        for (MarkerSplitSource unionSource : sources) {
            unionSource.addUnionSources(sources);
        }
        return sources;
    }
    // Must be a split source
    return ImmutableList.of((MarkerSplitSource) source);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) MarkerSplitSource(io.prestosql.snapshot.MarkerSplitSource) ArrayList(java.util.ArrayList) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId)

Example 3 with PlanFragmentId

use of io.prestosql.sql.planner.plan.PlanFragmentId in project hetu-core by openlookeng.

the class DistributedExecutionPlanner method plan.

public StageExecutionPlan plan(SubPlan root, Session session, Mode mode, Long resumeSnapshotId, long nextSnapshotId) {
    ImmutableList.Builder<SplitSource> allSplitSources = ImmutableList.builder();
    try {
        if (mode != Mode.SNAPSHOT) {
            return doPlan(mode, root, session, resumeSnapshotId, nextSnapshotId, allSplitSources, null, null, null);
        }
        // Capture dependencies among table scan sources. Only need to do this for the initial planning.
        // The leftmost source of each fragment. Key is fragment id; value is SplitSource or ValuesNode or RemoteSourceNode
        Map<PlanFragmentId, Object> leftmostSources = new HashMap<>();
        // Source dependency. Key is SplitSource or ValuesNode or RemoteSourceNode; value is SplitSource or ValuesNode or RemoteSourceNode
        Multimap<Object, Object> sourceDependencies = HashMultimap.create();
        // List of sources from the same union. Values are SplitSource or ValuesNode or RemoteSourceNode.
        List<List<Object>> unionSources = new ArrayList<>();
        StageExecutionPlan ret = doPlan(mode, root, session, resumeSnapshotId, nextSnapshotId, allSplitSources, leftmostSources, sourceDependencies, unionSources);
        for (Map.Entry<Object, Object> entry : sourceDependencies.entries()) {
            List<MarkerSplitSource> right = collectSources(leftmostSources, entry.getValue());
            for (MarkerSplitSource source : collectSources(leftmostSources, entry.getKey())) {
                for (SplitSource dependency : right) {
                    source.addDependency((MarkerSplitSource) dependency);
                }
            }
        }
        List<MarkerSplitSource> sources = new ArrayList<>();
        for (List<Object> union : unionSources) {
            sources.clear();
            for (Object unionSource : union) {
                sources.addAll(collectSources(leftmostSources, unionSource));
            }
            // Adding all these sources as "union dependencies" for each other, to make sure they produce the same set of markers.
            for (MarkerSplitSource source : sources) {
                source.addUnionSources(sources);
            }
        }
        return ret;
    } catch (Throwable t) {
        allSplitSources.build().forEach(DistributedExecutionPlanner::closeSplitSource);
        throw t;
    }
}
Also used : HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) MarkerSplitSource(io.prestosql.snapshot.MarkerSplitSource) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) SplitSource(io.prestosql.split.SplitSource) SampledSplitSource(io.prestosql.split.SampledSplitSource) MarkerSplitSource(io.prestosql.snapshot.MarkerSplitSource) SplitCacheMap(io.prestosql.execution.SplitCacheMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) HashMap(java.util.HashMap)

Example 4 with PlanFragmentId

use of io.prestosql.sql.planner.plan.PlanFragmentId in project hetu-core by openlookeng.

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 : RUNNING(io.prestosql.execution.StageState.RUNNING) InternalPlanVisitor(io.prestosql.sql.planner.plan.InternalPlanVisitor) SCHEDULED(io.prestosql.execution.StageState.SCHEDULED) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) LinkedHashSet(java.util.LinkedHashSet) JoinNode(io.prestosql.spi.plan.JoinNode) PlanFragment(io.prestosql.sql.planner.PlanFragment) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) PlanNode(io.prestosql.spi.plan.PlanNode) IndexJoinNode(io.prestosql.sql.planner.plan.IndexJoinNode) SpatialJoinNode(io.prestosql.sql.planner.plan.SpatialJoinNode) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) StageState(io.prestosql.execution.StageState) Ordering(com.google.common.collect.Ordering) Function.identity(java.util.function.Function.identity) UnionNode(io.prestosql.spi.plan.UnionNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SqlStageExecution(io.prestosql.execution.SqlStageExecution) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) InternalPlanVisitor(io.prestosql.sql.planner.plan.InternalPlanVisitor) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) PlanFragment(io.prestosql.sql.planner.PlanFragment) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with PlanFragmentId

use of io.prestosql.sql.planner.plan.PlanFragmentId in project hetu-core by openlookeng.

the class TestSqlStageExecution method createExchangePlanFragment.

private static PlanFragment createExchangePlanFragment() {
    PlanNode planNode = new RemoteSourceNode(new PlanNodeId("exchange"), ImmutableList.of(new PlanFragmentId("source")), ImmutableList.of(new Symbol("column")), Optional.empty(), REPARTITION);
    ImmutableMap.Builder<Symbol, Type> types = ImmutableMap.builder();
    for (Symbol symbol : planNode.getOutputSymbols()) {
        types.put(symbol, VARCHAR);
    }
    return new PlanFragment(new PlanFragmentId("exchange_fragment_id"), planNode, types.build(), SOURCE_DISTRIBUTION, ImmutableList.of(planNode.getId()), new PartitioningScheme(Partitioning.create(SINGLE_DISTRIBUTION, ImmutableList.of()), planNode.getOutputSymbols()), ungroupedExecution(), StatsAndCosts.empty(), Optional.empty(), Optional.empty(), Optional.empty());
}
Also used : PlanNodeId(io.prestosql.spi.plan.PlanNodeId) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) Type(io.prestosql.spi.type.Type) PlanNode(io.prestosql.spi.plan.PlanNode) Symbol(io.prestosql.spi.plan.Symbol) PartitioningScheme(io.prestosql.sql.planner.PartitioningScheme) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId) ImmutableMap(com.google.common.collect.ImmutableMap) PlanFragment(io.prestosql.sql.planner.PlanFragment)

Aggregations

PlanFragmentId (io.prestosql.sql.planner.plan.PlanFragmentId)10 PlanFragment (io.prestosql.sql.planner.PlanFragment)8 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)5 Symbol (io.prestosql.spi.plan.Symbol)5 PartitioningScheme (io.prestosql.sql.planner.PartitioningScheme)5 RemoteSourceNode (io.prestosql.sql.planner.plan.RemoteSourceNode)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 PlanNode (io.prestosql.spi.plan.PlanNode)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 MarkerSplitSource (io.prestosql.snapshot.MarkerSplitSource)2 JoinNode (io.prestosql.spi.plan.JoinNode)2 TableScanNode (io.prestosql.spi.plan.TableScanNode)2 ValuesNode (io.prestosql.spi.plan.ValuesNode)2 Type (io.prestosql.spi.type.Type)2 TestingColumnHandle (io.prestosql.testing.TestingMetadata.TestingColumnHandle)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2