public static Property<PlanNode, PlanNode> source() { return optionalProperty("source", node -> node.getSources().size() == 1 ? Optional.of(node.getSources().get(0)) : Optional.empty()); }
@Override protected Integer visitPlan(PlanNode node, Void context) { int count = 0; for (PlanNode source : node.getSources()) { count += source.accept(this, context); } return count; } }
private Void processChildren(PlanNode node, int indent) { for (PlanNode child : node.getSources()) { child.accept(this, indent); } return null; }
@Override protected Void visitPlan(PlanNode node, Void context) { node.getSources().forEach(source -> source.accept(this, context)); return null; }
private Void processChildren(PlanNode node, IOPlanBuilder context) { for (PlanNode child : node.getSources()) { child.accept(this, context); } return null; } }
@Override protected Optional<SeenExchanges> visitPlan(PlanNode node, Void context) { return aggregatedSeenExchanges(node.getSources()); }
@Override protected Void visitPlan(PlanNode node, Consumer<PlanNodeId> schedulingOrder) { for (PlanNode source : node.getSources()) { source.accept(this, schedulingOrder); } return null; }
@Override protected Void visitPlan(PlanNode node, C context) { for (PlanNode source : node.getSources()) { source.accept(this, context); } return null; } }
@Override protected Void visitPlan(PlanNode node, Void context) { for (PlanNode child : node.getSources()) { child.accept(this, context); } return null; } }
private <T extends PlanNode> void findAllRecursive(PlanNode node, ImmutableList.Builder<T> nodes) { node = lookup.resolve(node); if (where.test(node)) { nodes.add((T) node); } if (recurseOnlyWhen.test(node)) { for (PlanNode source : node.getSources()) { findAllRecursive(source, nodes); } } }
private static void findSources(PlanNode node, Set<PlanNodeId> nodeIds, ImmutableSet.Builder<PlanNode> nodes) { if (nodeIds.contains(node.getId())) { nodes.add(node); } for (PlanNode source : node.getSources()) { nodes.addAll(findSources(source, nodeIds)); } }
/** * Transforms a plan like P->C->X to C->P->X */ public static PlanNode transpose(PlanNode parent, PlanNode child) { return child.replaceChildren(ImmutableList.of( parent.replaceChildren( child.getSources()))); }
public static StreamProperties derivePropertiesRecursively(PlanNode node, Metadata metadata, Session session, TypeProvider types, SqlParser parser) { List<StreamProperties> inputProperties = node.getSources().stream() .map(source -> derivePropertiesRecursively(source, metadata, session, types, parser)) .collect(toImmutableList()); return StreamPropertyDerivations.deriveProperties(node, inputProperties, metadata, session, types, parser); }
public static ActualProperties derivePropertiesRecursively(PlanNode node, Metadata metadata, Session session, TypeProvider types, SqlParser parser) { List<ActualProperties> inputProperties = node.getSources().stream() .map(source -> derivePropertiesRecursively(source, metadata, session, types, parser)) .collect(toImmutableList()); return deriveProperties(node, inputProperties, metadata, session, types, parser); }
/** * Invoke the rewrite logic recursively on children of the given node and swap it * out with an identical copy with the rewritten children */ public PlanNode defaultRewrite(PlanNode node, C context) { List<PlanNode> children = node.getSources().stream() .map(child -> rewrite(child, context)) .collect(toImmutableList()); return replaceChildren(node, children); }
public StatsCalculatorAssertion withSourceStats(int sourceIndex, PlanNodeStatsEstimate sourceStats) { checkArgument(sourceIndex < planNode.getSources().size(), "invalid sourceIndex %s; planNode has %s sources", sourceIndex, planNode.getSources().size()); sourcesStats.put(planNode.getSources().get(sourceIndex), sourceStats); return this; }
private PlanNode insertChildrenAndRewrite(PlanNode node) { return node.replaceChildren( node.getSources().stream() .map(child -> new GroupReference( idAllocator.getNextId(), insertRecursive(child), child.getOutputSymbols())) .collect(Collectors.toList())); }
private static void assertMatchesStructure(PlanNode actual, PlanNode expected) { assertEquals(actual.getClass(), expected.getClass()); assertEquals(actual.getId(), expected.getId()); assertEquals(actual.getSources().size(), expected.getSources().size()); for (int i = 0; i < actual.getSources().size(); i++) { assertMatchesStructure(actual.getSources().get(i), expected.getSources().get(i)); } }
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); }
@Override public Result apply(PlanNode node, Captures captures, Context context) { return Result.ofPlanNode(node.replaceChildren(node.getSources())); } }