Refine search
@Override public Void visitUnnest(UnnestNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); Set<Symbol> required = ImmutableSet.<Symbol>builder() .addAll(node.getReplicateSymbols()) .addAll(node.getUnnestSymbols().keySet()) .build(); checkDependencies(source.getOutputSymbols(), required, "Invalid node. Dependencies (%s) not in source plan output (%s)", required, source.getOutputSymbols()); return null; }
private PlanNode distinct(PlanNode node) { return new AggregationNode(idAllocator.getNextId(), node, ImmutableMap.of(), singleGroupingSet(node.getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty()); }
@Override public Optional<DecorrelationResult> visitLimit(LimitNode node, Void context) Optional<DecorrelationResult> childDecorrelationResultOptional = lookup.resolve(node.getSource()).accept(this, null); if (!childDecorrelationResultOptional.isPresent() || node.getCount() == 0) { return Optional.empty(); PlanNode decorrelatedChildNode = childDecorrelationResult.node; if (constantSymbols.isEmpty() || !constantSymbols.containsAll(decorrelatedChildNode.getOutputSymbols())) { return Optional.empty(); idAllocator.getNextId(), decorrelatedChildNode, ImmutableMap.of(), singleGroupingSet(decorrelatedChildNode.getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE,
private UnionNode union(List<PlanNode> nodes, List<Symbol> outputs) { ImmutableListMultimap.Builder<Symbol, Symbol> outputsToInputs = ImmutableListMultimap.builder(); for (PlanNode source : nodes) { for (int i = 0; i < source.getOutputSymbols().size(); i++) { outputsToInputs.put(outputs.get(i), source.getOutputSymbols().get(i)); } } return new UnionNode(idAllocator.getNextId(), nodes, outputsToInputs.build(), outputs); }
@Override public Void visitGroupId(GroupIdNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child checkDependencies(source.getOutputSymbols(), node.getInputSymbols(), "Invalid node. Grouping symbols (%s) not in source plan output (%s)", node.getInputSymbols(), source.getOutputSymbols()); return null; }
@Override public PlanWithProperties visitTableWriter(TableWriterNode node, PreferredProperties preferredProperties) { PlanWithProperties source = node.getSource().accept(this, preferredProperties); Optional<PartitioningScheme> partitioningScheme = node.getPartitioningScheme(); if (!partitioningScheme.isPresent()) { if (scaleWriters) { partitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(SCALED_WRITER_DISTRIBUTION, ImmutableList.of()), source.getNode().getOutputSymbols())); } else if (redistributeWrites) { partitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(FIXED_ARBITRARY_DISTRIBUTION, ImmutableList.of()), source.getNode().getOutputSymbols())); } } if (partitioningScheme.isPresent() && !source.getProperties().isCompatibleTablePartitioningWith(partitioningScheme.get().getPartitioning(), false, metadata, session)) { source = withDerivedProperties( partitionedExchange( idAllocator.getNextId(), REMOTE, source.getNode(), partitioningScheme.get()), source.getProperties()); } return rebaseAndDeriveProperties(node, source); }
private static PlanNode createIndexJoinWithExpectedOutputs(List<Symbol> expectedOutputs, IndexJoinNode.Type type, PlanNode probe, PlanNode index, List<IndexJoinNode.EquiJoinClause> equiJoinClause, PlanNodeIdAllocator idAllocator) { PlanNode result = new IndexJoinNode(idAllocator.getNextId(), type, probe, index, equiJoinClause, Optional.empty(), Optional.empty()); if (!result.getOutputSymbols().equals(expectedOutputs)) { result = new ProjectNode( idAllocator.getNextId(), result, Assignments.identity(expectedOutputs)); } return result; }
@Override public Void visitMarkDistinct(MarkDistinctNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child checkDependencies(source.getOutputSymbols(), node.getDistinctSymbols(), "Invalid node. Mark distinct symbols (%s) not in source plan output (%s)", node.getDistinctSymbols(), source.getOutputSymbols()); return null; }
.build(); PlanWithProperties source = node.getSources().get(sourceIndex).accept(this, childPreferred); if (!source.getProperties().isCompatibleTablePartitioningWith(childPartitioning, nullsAndAnyReplicated, metadata, session)) { source = withDerivedProperties( partitionedExchange( idAllocator.getNextId(), REMOTE, source.getNode(), new PartitioningScheme( childPartitioning, source.getNode().getOutputSymbols(), Optional.empty(), nullsAndAnyReplicated, PlanWithProperties child = node.getSources().get(i).accept(this, PreferredProperties.any()); plannedChildren.add(child); if (child.getProperties().isSingleNode()) { idAllocator.getNextId(), GATHER, REMOTE, idAllocator.getNextId(), GATHER, REMOTE, unpartitionedOutputLayouts.add(result.getOutputSymbols());
/** * @return If the node has outputs not in permittedOutputs, returns an identity projection containing only those node outputs also in permittedOutputs. */ public static Optional<PlanNode> restrictOutputs(PlanNodeIdAllocator idAllocator, PlanNode node, Set<Symbol> permittedOutputs) { List<Symbol> restrictedOutputs = node.getOutputSymbols().stream() .filter(permittedOutputs::contains) .collect(toImmutableList()); if (restrictedOutputs.size() == node.getOutputSymbols().size()) { return Optional.empty(); } return Optional.of( new ProjectNode( idAllocator.getNextId(), node, Assignments.identity(restrictedOutputs))); }
@Override public Void visitOutput(OutputNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child checkDependencies(source.getOutputSymbols(), node.getOutputSymbols(), "Invalid node. Output column dependencies (%s) not in source plan output (%s)", node.getOutputSymbols(), source.getOutputSymbols()); return null; }
SetMultimap<Symbol, Symbol> filteringToSource = createMapping(filteringSourceSymbols, sourceSymbols); source = node.getSource().accept(this, PreferredProperties.partitioned(ImmutableSet.copyOf(sourceSymbols))); filteringSource = node.getFilteringSource().accept(this, PreferredProperties.partitionedWithNullsAndAnyReplicated(filteringPartitioning)); if (!source.getProperties().withReplicatedNulls(true).isCompatibleTablePartitioningWith(filteringSource.getProperties(), sourceToFiltering::get, metadata, session)) { filteringSource = withDerivedProperties( partitionedExchange(idAllocator.getNextId(), REMOTE, filteringSource.getNode(), new PartitioningScheme( filteringPartitioning, filteringSource.getNode().getOutputSymbols(), Optional.empty(), true, filteringSource = node.getFilteringSource().accept(this, PreferredProperties.partitionedWithNullsAndAnyReplicated(ImmutableSet.copyOf(filteringSourceSymbols))); partitionedExchange(idAllocator.getNextId(), REMOTE, source.getNode(), new PartitioningScheme(sourcePartitioning, source.getNode().getOutputSymbols())), source.getProperties()); partitionedExchange(idAllocator.getNextId(), REMOTE, source.getNode(), sourceSymbols, Optional.empty()), source.getProperties()); filteringSource = withDerivedProperties( partitionedExchange(idAllocator.getNextId(), REMOTE, filteringSource.getNode(), new PartitioningScheme( filteringPartitioning, filteringSource.getNode().getOutputSymbols(), Optional.empty(), true,
private PlanNode insertChildrenAndRewrite(PlanNode node) { return node.replaceChildren( node.getSources().stream() .map(child -> new GroupReference( idAllocator.getNextId(), insertRecursive(child), child.getOutputSymbols())) .collect(Collectors.toList())); }
@Override public Void visitDistinctLimit(DistinctLimitNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child checkDependencies(source.getOutputSymbols(), node.getOutputSymbols(), "Invalid node. Output column dependencies (%s) not in source plan output (%s)", node.getOutputSymbols(), source.getOutputSymbols()); return null; }
right = node.getRight().accept(this, PreferredProperties.partitioned(rightPartitioning)); if (!right.getProperties().isCompatibleTablePartitioningWith(left.getProperties(), rightToLeft::get, metadata, session)) { right = withDerivedProperties( partitionedExchange(idAllocator.getNextId(), REMOTE, right.getNode(), new PartitioningScheme(rightPartitioning, right.getNode().getOutputSymbols())), right.getProperties()); right = node.getRight().accept(this, PreferredProperties.partitioned(ImmutableSet.copyOf(rightSymbols))); partitionedExchange(idAllocator.getNextId(), REMOTE, left.getNode(), new PartitioningScheme(leftPartitioning, left.getNode().getOutputSymbols())), left.getProperties()); partitionedExchange(idAllocator.getNextId(), REMOTE, left.getNode(), leftSymbols, Optional.empty()), left.getProperties()); right = withDerivedProperties( Partitioning rightPartitioning = left.getProperties().translate(createTranslator(leftToRight)).getNodePartitioning().get(); right = withDerivedProperties( partitionedExchange(idAllocator.getNextId(), REMOTE, right.getNode(), new PartitioningScheme(rightPartitioning, right.getNode().getOutputSymbols())), right.getProperties());
@Override public Result apply(LateralJoinNode lateralJoinNode, Captures captures, Context context) { return Result.ofPlanNode(new JoinNode( context.getIdAllocator().getNextId(), JoinNode.Type.INNER, lateralJoinNode.getInput(), lateralJoinNode.getSubquery(), ImmutableList.of(), ImmutableList.<Symbol>builder() .addAll(lateralJoinNode.getInput().getOutputSymbols()) .addAll(lateralJoinNode.getSubquery().getOutputSymbols()) .build(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty())); } }
@Override public Map<Symbol, Symbol> visitIndexJoin(IndexJoinNode node, Set<Symbol> lookupSymbols) { Set<Symbol> probeLookupSymbols = lookupSymbols.stream() .filter(node.getProbeSource().getOutputSymbols()::contains) .collect(toImmutableSet()); checkState(!probeLookupSymbols.isEmpty(), "No lookup symbols were able to pass through the index join probe source"); return node.getProbeSource().accept(this, probeLookupSymbols); }
private PlanBuilder distinct(PlanBuilder subPlan, QuerySpecification node) { if (node.getSelect().isDistinct()) { return subPlan.withNewRoot( new AggregationNode( idAllocator.getNextId(), subPlan.getRoot(), ImmutableMap.of(), singleGroupingSet(subPlan.getRoot().getOutputSymbols()), ImmutableList.of(), AggregationNode.Step.SINGLE, Optional.empty(), Optional.empty())); } return subPlan; }
@Override public Void visitDelete(DeleteNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child checkArgument(source.getOutputSymbols().contains(node.getRowId()), "Invalid node. Row ID symbol (%s) is not in source plan output (%s)", node.getRowId(), node.getSource().getOutputSymbols()); return null; }
private ProjectNode projectExpressions(PlanNode input, Assignments subqueryAssignments) { Assignments assignments = Assignments.builder() .putIdentities(input.getOutputSymbols()) .putAll(subqueryAssignments) .build(); return new ProjectNode( idAllocator.getNextId(), input, assignments); } }