@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new UnionNode(getId(), newChildren, getSymbolMapping(), getOutputSymbols()); } }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<Boolean> context) { ImmutableList.Builder<PlanNode> flattenedSources = ImmutableList.builder(); ImmutableListMultimap.Builder<Symbol, Symbol> flattenedSymbolMap = ImmutableListMultimap.builder(); flattenSetOperation(node, context, flattenedSources, flattenedSymbolMap); return new UnionNode(node.getId(), flattenedSources.build(), flattenedSymbolMap.build(), ImmutableList.copyOf(flattenedSymbolMap.build().keySet())); }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<Set<Symbol>> context) { ListMultimap<Symbol, Symbol> rewrittenSymbolMapping = rewriteSetOperationSymbolMapping(node, context); ImmutableList<PlanNode> rewrittenSubPlans = rewriteSetOperationSubPlans(node, context, rewrittenSymbolMapping); return new UnionNode(node.getId(), rewrittenSubPlans, rewrittenSymbolMapping, ImmutableList.copyOf(rewrittenSymbolMapping.keySet())); }
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 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<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<Void> context) { return new UnionNode(node.getId(), rewriteSources(node, context).build(), canonicalizeSetOperationSymbolMap(node.getSymbolMapping()), canonicalizeAndDistinct(node.getOutputSymbols())); }
public UnionNode union(ListMultimap<Symbol, Symbol> outputsToInputs, List<PlanNode> sources) { ImmutableList<Symbol> outputs = outputsToInputs.keySet().stream().collect(toImmutableList()); return new UnionNode(idAllocator.getNextId(), sources, outputsToInputs, outputs); }
new UnionNode( node.getId(), newSources.build(),
@Override protected RelationPlan visitUnion(Union node, Void context) { checkArgument(!node.getRelations().isEmpty(), "No relations specified for UNION"); SetOperationPlan setOperationPlan = process(node); PlanNode planNode = new UnionNode(idAllocator.getNextId(), setOperationPlan.getSources(), setOperationPlan.getSymbolMapping(), ImmutableList.copyOf(setOperationPlan.getSymbolMapping().keySet())); if (node.isDistinct()) { planNode = distinct(planNode); } return new RelationPlan(planNode, analysis.getScope(node), planNode.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())); } }
@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; }
return Result.ofPlanNode(new UnionNode(parent.getId(), outputSources.build(), mappings.build(), ImmutableList.copyOf(mappings.build().keySet())));
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'output(_[0-9]+)?' is expected to be date, but the actual type is bigint") public void testInvalidUnion() { Symbol outputSymbol = symbolAllocator.newSymbol("output", DATE); ListMultimap<Symbol, Symbol> mappings = ImmutableListMultimap.<Symbol, Symbol>builder() .put(outputSymbol, columnD) .put(outputSymbol, columnA) // should be a symbol with DATE type .build(); PlanNode node = new UnionNode( newId(), ImmutableList.of(baseTableScan, baseTableScan), mappings, ImmutableList.copyOf(mappings.keySet())); assertTypesValid(node); }
@Test public void testValidUnion() { Symbol outputSymbol = symbolAllocator.newSymbol("output", DATE); ListMultimap<Symbol, Symbol> mappings = ImmutableListMultimap.<Symbol, Symbol>builder() .put(outputSymbol, columnD) .put(outputSymbol, columnD) .build(); PlanNode node = new UnionNode( newId(), ImmutableList.of(baseTableScan, baseTableScan), mappings, ImmutableList.copyOf(mappings.keySet())); assertTypesValid(node); }
private static PlanFragment createUnionPlanFragment(String name, PlanFragment... fragments) { PlanNode planNode = new UnionNode( new PlanNodeId(name + "_id"), Stream.of(fragments) .map(fragment -> new RemoteSourceNode(new PlanNodeId(fragment.getId().toString()), fragment.getId(), fragment.getPartitioningScheme().getOutputLayout(), Optional.empty(), REPARTITION)) .collect(toImmutableList()), ImmutableListMultimap.of(), ImmutableList.of()); return createFragment(planNode); }
@Test public void testUnion() { ImmutableListMultimap<Symbol, Symbol> symbolMapping = ImmutableListMultimap.of(A, B, A, C, A, E); PlanNode node = new UnionNode(newId(), ImmutableList.of( filter(baseTableScan, greaterThan(AE, bigintLiteral(10))), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100)))), filter(baseTableScan, and(greaterThan(AE, bigintLiteral(10)), lessThan(AE, bigintLiteral(100))))), symbolMapping, ImmutableList.copyOf(symbolMapping.keySet())); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Only the common conjuncts can be inferred through a Union assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(greaterThan(AE, bigintLiteral(10)))); }
@Test public void testUnion() { TableScanNode ts1 = tableScan("ts1", "orderkey"); TableScanNode ts2 = tableScan("ts2", "orderkey_0"); ImmutableListMultimap.Builder<Symbol, Symbol> outputMappings = ImmutableListMultimap.builder(); outputMappings.put(new Symbol("orderkey_1"), new Symbol("orderkey")); outputMappings.put(new Symbol("orderkey_1"), new Symbol("orderkey_0")); UnionNode union = new UnionNode(new PlanNodeId("union"), ImmutableList.of(ts1, ts2), outputMappings.build(), ImmutableList.of(new Symbol("orderkey_1"))); Map<String, PlanNodeStatsEstimate> stats = ImmutableMap.of( "ts1", statsEstimate(ts1, 4000), "ts2", statsEstimate(ts2, 1000), "union", statsEstimate(ts1, 5000)); Map<String, PlanNodeCostEstimate> costs = ImmutableMap.of( "ts1", cpuCost(1000), "ts2", cpuCost(1000)); Map<String, Type> types = ImmutableMap.of( "orderkey", BIGINT, "orderkey_0", BIGINT, "orderkey_1", BIGINT); assertCost(union, costs, stats, types) .cpu(2000) .memory(0) .network(0); assertCostEstimatedExchanges(union, costs, stats, types) .cpu(2000) .memory(0) .network(5000 * IS_NULL_OVERHEAD); }
@Override public PlanNode visitUnion(UnionNode node, List<PlanNode> newChildren) { return new UnionNode(node.getId(), newChildren, node.getSymbolMapping(), node.getOutputSymbols()); }