@Override public Void visitUnion(UnionNode node, Void context) { for (PlanNode subPlanNode : node.getSources()) { subPlanNode.accept(this, context); } return null; }
@Override public Void visitUnion(UnionNode node, Void context) { for (PlanNode subPlanNode : node.getSources()) { subPlanNode.accept(this, context); } return null; }
@Override public Map<PlanNodeId, SplitSource> visitUnion(UnionNode node, Void context) { return processSources(node.getSources(), context); }
@Override public Map<PlanNodeId, SplitSource> visitUnion(UnionNode node, Void context) { return processSources(node.getSources(), context); }
@Override public Set<PlanFragmentId> visitUnion(UnionNode node, PlanFragmentId currentFragmentId) { ImmutableSet.Builder<PlanFragmentId> allSources = ImmutableSet.builder(); // Link the source fragments together, so we only schedule one at a time. Set<PlanFragmentId> previousSources = ImmutableSet.of(); for (PlanNode subPlanNode : node.getSources()) { Set<PlanFragmentId> currentSources = subPlanNode.accept(this, currentFragmentId); allSources.addAll(currentSources); addEdges(previousSources, currentSources); previousSources = currentSources; } return allSources.build(); }
@Override protected final Optional<PlanNodeStatsEstimate> doCalculate(UnionNode node, StatsProvider statsProvider, Lookup lookup, Session session, TypeProvider types) { checkArgument(!node.getSources().isEmpty(), "Empty Union is not supported"); Optional<PlanNodeStatsEstimate> estimate = Optional.empty(); for (int i = 0; i < node.getSources().size(); i++) { PlanNode source = node.getSources().get(i); PlanNodeStatsEstimate sourceStats = statsProvider.getStats(source); PlanNodeStatsEstimate sourceStatsWithMappedSymbols = mapToOutputSymbols(sourceStats, node.getSymbolMapping(), i); if (estimate.isPresent()) { estimate = Optional.of(addStatsAndCollapseDistinctValues(estimate.get(), sourceStatsWithMappedSymbols)); } else { estimate = Optional.of(sourceStatsWithMappedSymbols); } } return estimate; }
@Override public Set<PlanFragmentId> visitUnion(UnionNode node, PlanFragmentId currentFragmentId) { ImmutableSet.Builder<PlanFragmentId> allSources = ImmutableSet.builder(); // Link the source fragments together, so we only schedule one at a time. Set<PlanFragmentId> previousSources = ImmutableSet.of(); for (PlanNode subPlanNode : node.getSources()) { Set<PlanFragmentId> currentSources = subPlanNode.accept(this, currentFragmentId); allSources.addAll(currentSources); addEdges(previousSources, currentSources); previousSources = currentSources; } return allSources.build(); }
@Override protected final Optional<PlanNodeStatsEstimate> doCalculate(UnionNode node, StatsProvider statsProvider, Lookup lookup, Session session, TypeProvider types) { checkArgument(!node.getSources().isEmpty(), "Empty Union is not supported"); Optional<PlanNodeStatsEstimate> estimate = Optional.empty(); for (int i = 0; i < node.getSources().size(); i++) { PlanNode source = node.getSources().get(i); PlanNodeStatsEstimate sourceStats = statsProvider.getStats(source); PlanNodeStatsEstimate sourceStatsWithMappedSymbols = mapToOutputSymbols(sourceStats, node.getSymbolMapping(), i); if (estimate.isPresent()) { estimate = Optional.of(addStatsAndCollapseDistinctValues(estimate.get(), sourceStatsWithMappedSymbols)); } else { estimate = Optional.of(sourceStatsWithMappedSymbols); } } return estimate; }
@Override public Void visitUnion(UnionNode node, Void context) { printNode(node, "Union", NODE_COLORS.get(NodeType.UNION)); for (PlanNode planNode : node.getSources()) { planNode.accept(this, context); } return null; }
@Override public Void visitUnion(UnionNode node, Void context) { printNode(node, "Union", NODE_COLORS.get(NodeType.UNION)); for (PlanNode planNode : node.getSources()) { planNode.accept(this, context); } return null; }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<Expression> context) { boolean modified = false; ImmutableList.Builder<PlanNode> builder = ImmutableList.builder(); for (int i = 0; i < node.getSources().size(); i++) { Expression sourcePredicate = inlineSymbols(node.sourceSymbolMap(i), context.get()); PlanNode source = node.getSources().get(i); PlanNode rewrittenSource = context.rewrite(source, sourcePredicate); if (rewrittenSource != source) { modified = true; } builder.add(rewrittenSource); } if (modified) { return new UnionNode(node.getId(), builder.build(), node.getSymbolMapping(), node.getOutputSymbols()); } return node; }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<Expression> context) { boolean modified = false; ImmutableList.Builder<PlanNode> builder = ImmutableList.builder(); for (int i = 0; i < node.getSources().size(); i++) { Expression sourcePredicate = inlineSymbols(node.sourceSymbolMap(i), context.get()); PlanNode source = node.getSources().get(i); PlanNode rewrittenSource = context.rewrite(source, sourcePredicate); if (rewrittenSource != source) { modified = true; } builder.add(rewrittenSource); } if (modified) { return new UnionNode(node.getId(), builder.build(), node.getSymbolMapping(), node.getOutputSymbols()); } return node; }
@Override public Result apply(TableWriterNode writerNode, Captures captures, Context context) { UnionNode unionNode = captures.get(CHILD); ImmutableList.Builder<PlanNode> rewrittenSources = ImmutableList.builder(); List<Map<Symbol, Symbol>> sourceMappings = new ArrayList<>(); for (int source = 0; source < unionNode.getSources().size(); source++) { rewrittenSources.add(rewriteSource(writerNode, unionNode, source, sourceMappings, context)); } ImmutableListMultimap.Builder<Symbol, Symbol> unionMappings = ImmutableListMultimap.builder(); sourceMappings.forEach(mappings -> mappings.forEach(unionMappings::put)); return Result.ofPlanNode( new UnionNode( context.getIdAllocator().getNextId(), rewrittenSources.build(), unionMappings.build(), ImmutableList.copyOf(unionMappings.build().keySet()))); }
@Override public Result apply(TableWriterNode writerNode, Captures captures, Context context) { UnionNode unionNode = captures.get(CHILD); ImmutableList.Builder<PlanNode> rewrittenSources = ImmutableList.builder(); List<Map<Symbol, Symbol>> sourceMappings = new ArrayList<>(); for (int source = 0; source < unionNode.getSources().size(); source++) { rewrittenSources.add(rewriteSource(writerNode, unionNode, source, sourceMappings, context)); } ImmutableListMultimap.Builder<Symbol, Symbol> unionMappings = ImmutableListMultimap.builder(); sourceMappings.forEach(mappings -> mappings.forEach(unionMappings::put)); return Result.ofPlanNode( new UnionNode( context.getIdAllocator().getNextId(), rewrittenSources.build(), unionMappings.build(), ImmutableList.copyOf(unionMappings.build().keySet()))); }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); LimitContext childLimit = null; if (limit != null) { childLimit = new LimitContext(limit.getCount(), true); } List<PlanNode> sources = new ArrayList<>(); for (int i = 0; i < node.getSources().size(); i++) { sources.add(context.rewrite(node.getSources().get(i), childLimit)); } PlanNode output = new UnionNode(node.getId(), sources, node.getSymbolMapping(), node.getOutputSymbols()); if (limit != null) { output = new LimitNode(idAllocator.getNextId(), output, limit.getCount(), limit.isPartial()); } return output; }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<LimitContext> context) { LimitContext limit = context.get(); LimitContext childLimit = null; if (limit != null) { childLimit = new LimitContext(limit.getCount(), true); } List<PlanNode> sources = new ArrayList<>(); for (int i = 0; i < node.getSources().size(); i++) { sources.add(context.rewrite(node.getSources().get(i), childLimit)); } PlanNode output = new UnionNode(node.getId(), sources, node.getSymbolMapping(), node.getOutputSymbols()); if (limit != null) { output = new LimitNode(idAllocator.getNextId(), output, limit.getCount(), limit.isPartial()); } return output; }
@Override public Result apply(TopNNode topNNode, Captures captures, Context context) { UnionNode unionNode = captures.get(CHILD); ImmutableList.Builder<PlanNode> sources = ImmutableList.builder(); for (PlanNode source : unionNode.getSources()) { SymbolMapper.Builder symbolMapper = SymbolMapper.builder(); Set<Symbol> sourceOutputSymbols = ImmutableSet.copyOf(source.getOutputSymbols()); for (Symbol unionOutput : unionNode.getOutputSymbols()) { Set<Symbol> inputSymbols = ImmutableSet.copyOf(unionNode.getSymbolMapping().get(unionOutput)); Symbol unionInput = getLast(intersection(inputSymbols, sourceOutputSymbols)); symbolMapper.put(unionOutput, unionInput); } sources.add(symbolMapper.build().map(topNNode, source, context.getIdAllocator().getNextId())); } return Result.ofPlanNode(new UnionNode( unionNode.getId(), sources.build(), unionNode.getSymbolMapping(), unionNode.getOutputSymbols())); } }
@Override public Result apply(TopNNode topNNode, Captures captures, Context context) { UnionNode unionNode = captures.get(CHILD); ImmutableList.Builder<PlanNode> sources = ImmutableList.builder(); for (PlanNode source : unionNode.getSources()) { SymbolMapper.Builder symbolMapper = SymbolMapper.builder(); Set<Symbol> sourceOutputSymbols = ImmutableSet.copyOf(source.getOutputSymbols()); for (Symbol unionOutput : unionNode.getOutputSymbols()) { Set<Symbol> inputSymbols = ImmutableSet.copyOf(unionNode.getSymbolMapping().get(unionOutput)); Symbol unionInput = getLast(intersection(inputSymbols, sourceOutputSymbols)); symbolMapper.put(unionOutput, unionInput); } sources.add(symbolMapper.build().map(topNNode, source, context.getIdAllocator().getNextId())); } return Result.ofPlanNode(new UnionNode( unionNode.getId(), sources.build(), unionNode.getSymbolMapping(), unionNode.getOutputSymbols())); } }
private Partitioning selectUnionPartitioning(UnionNode node, PreferredProperties preferredProperties, PreferredProperties.PartitioningProperties parentPreference) { // Use the parent's requested partitioning if available if (parentPreference.getPartitioning().isPresent()) { return parentPreference.getPartitioning().get(); } // Try planning the children to see if any of them naturally produce a partitioning (for now, just select the first) boolean nullsAndAnyReplicated = parentPreference.isNullsAndAnyReplicated(); for (int sourceIndex = 0; sourceIndex < node.getSources().size(); sourceIndex++) { PreferredProperties.PartitioningProperties childPartitioning = parentPreference.translate(outputToInputTranslator(node, sourceIndex)).get(); PreferredProperties childPreferred = PreferredProperties.builder() .global(PreferredProperties.Global.distributed(childPartitioning.withNullsAndAnyReplicated(nullsAndAnyReplicated))) .build(); PlanWithProperties child = node.getSources().get(sourceIndex).accept(this, childPreferred); if (child.getProperties().isNodePartitionedOn(childPartitioning.getPartitioningColumns(), nullsAndAnyReplicated)) { Function<Symbol, Optional<Symbol>> childToParent = createTranslator(createMapping(node.sourceOutputLayout(sourceIndex), node.getOutputSymbols())); return child.getProperties().translate(childToParent).getNodePartitioning().get(); } } // Otherwise, choose an arbitrary partitioning over the columns return Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.copyOf(parentPreference.getPartitioningColumns())); }
private Partitioning selectUnionPartitioning(UnionNode node, PreferredProperties preferredProperties, PreferredProperties.PartitioningProperties parentPreference) { // Use the parent's requested partitioning if available if (parentPreference.getPartitioning().isPresent()) { return parentPreference.getPartitioning().get(); } // Try planning the children to see if any of them naturally produce a partitioning (for now, just select the first) boolean nullsAndAnyReplicated = parentPreference.isNullsAndAnyReplicated(); for (int sourceIndex = 0; sourceIndex < node.getSources().size(); sourceIndex++) { PreferredProperties.PartitioningProperties childPartitioning = parentPreference.translate(outputToInputTranslator(node, sourceIndex)).get(); PreferredProperties childPreferred = PreferredProperties.builder() .global(PreferredProperties.Global.distributed(childPartitioning.withNullsAndAnyReplicated(nullsAndAnyReplicated))) .build(); PlanWithProperties child = node.getSources().get(sourceIndex).accept(this, childPreferred); if (child.getProperties().isNodePartitionedOn(childPartitioning.getPartitioningColumns(), nullsAndAnyReplicated)) { Function<Symbol, Optional<Symbol>> childToParent = createTranslator(createMapping(node.sourceOutputLayout(sourceIndex), node.getOutputSymbols())); return child.getProperties().translate(childToParent).getNodePartitioning().get(); } } // Otherwise, choose an arbitrary partitioning over the columns return Partitioning.create(FIXED_HASH_DISTRIBUTION, ImmutableList.copyOf(parentPreference.getPartitioningColumns())); }