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());
}
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);
}
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;
}
}
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();
}
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());
}
Aggregations