private PlanWithProperties planAndEnforceChildren(PlanNode node, StreamPreferredProperties requiredProperties, StreamPreferredProperties preferredProperties) { // plan and enforce each child, but strip any requirement not in terms of symbols produced from the child // Note: this assumes the child uses the same symbols as the parent List<PlanWithProperties> children = node.getSources().stream() .map(source -> planAndEnforce( source, requiredProperties.constrainTo(source.getOutputSymbols()), preferredProperties.constrainTo(source.getOutputSymbols()))) .collect(toImmutableList()); return rebaseAndDeriveProperties(node, children); }
.constrainTo(node.getSource().getOutputSymbols()) .withDefaultParallelism(session) .withPartitioning(node.getPartitionBy());
@Override public PlanWithProperties visitIndexJoin(IndexJoinNode node, StreamPreferredProperties parentPreferences) { PlanWithProperties probe = planAndEnforce( node.getProbeSource(), defaultParallelism(session), parentPreferences.constrainTo(node.getProbeSource().getOutputSymbols()).withDefaultParallelism(session)); // index source does not support local parallel and must produce a single stream StreamProperties indexStreamProperties = derivePropertiesRecursively(node.getIndexSource(), metadata, session, types, parser); checkArgument(indexStreamProperties.getDistribution() == SINGLE, "index source must be single stream"); PlanWithProperties index = new PlanWithProperties(node.getIndexSource(), indexStreamProperties); return rebaseAndDeriveProperties(node, ImmutableList.of(probe, index)); }
@Override public PlanWithProperties visitSemiJoin(SemiJoinNode node, StreamPreferredProperties parentPreferences) { PlanWithProperties source = planAndEnforce( node.getSource(), defaultParallelism(session), parentPreferences.constrainTo(node.getSource().getOutputSymbols()).withDefaultParallelism(session)); // this filter source consumes the input completely, so we do not pass through parent preferences PlanWithProperties filteringSource = planAndEnforce(node.getFilteringSource(), singleStream(), singleStream()); return rebaseAndDeriveProperties(node, ImmutableList.of(source, filteringSource)); }
@Override public PlanWithProperties visitSpatialJoin(SpatialJoinNode node, StreamPreferredProperties parentPreferences) { PlanWithProperties probe = planAndEnforce( node.getLeft(), defaultParallelism(session), parentPreferences.constrainTo(node.getLeft().getOutputSymbols()) .withDefaultParallelism(session)); PlanWithProperties build = planAndEnforce(node.getRight(), singleStream(), singleStream()); return rebaseAndDeriveProperties(node, ImmutableList.of(probe, build)); }
@Override public PlanWithProperties visitJoin(JoinNode node, StreamPreferredProperties parentPreferences) { PlanWithProperties probe; if (isSpillEnabled(session)) { probe = planAndEnforce( node.getLeft(), fixedParallelism(), parentPreferences.constrainTo(node.getLeft().getOutputSymbols()).withFixedParallelism()); } else { probe = planAndEnforce( node.getLeft(), defaultParallelism(session), parentPreferences.constrainTo(node.getLeft().getOutputSymbols()).withDefaultParallelism(session)); } // this build consumes the input completely, so we do not pass through parent preferences List<Symbol> buildHashSymbols = Lists.transform(node.getCriteria(), JoinNode.EquiJoinClause::getRight); StreamPreferredProperties buildPreference; if (getTaskConcurrency(session) > 1) { buildPreference = exactlyPartitionedOn(buildHashSymbols); } else { buildPreference = singleStream(); } PlanWithProperties build = planAndEnforce(node.getRight(), buildPreference, buildPreference); return rebaseAndDeriveProperties(node, ImmutableList.of(probe, build)); }
.constrainTo(node.getSource().getOutputSymbols()) .withDefaultParallelism(session) .withPartitioning(groupingKeys);
@Override public PlanWithProperties visitMarkDistinct(MarkDistinctNode node, StreamPreferredProperties parentPreferences) { // mark distinct requires that all data partitioned StreamPreferredProperties childRequirements = parentPreferences .constrainTo(node.getSource().getOutputSymbols()) .withDefaultParallelism(session) .withPartitioning(node.getDistinctSymbols()); PlanWithProperties child = planAndEnforce(node.getSource(), childRequirements, childRequirements); MarkDistinctNode result = new MarkDistinctNode( node.getId(), child.getNode(), node.getMarkerSymbol(), pruneMarkDistinctSymbols(node, child.getProperties().getLocalProperties()), node.getHashSymbol()); return deriveProperties(result, child.getProperties()); }