/** * Returns the output to input symbol mapping for the given source channel */ public Map<Symbol, QualifiedNameReference> sourceSymbolMap(int sourceIndex) { ImmutableMap.Builder<Symbol, QualifiedNameReference> builder = ImmutableMap.<Symbol, QualifiedNameReference>builder(); for (Map.Entry<Symbol, Collection<Symbol>> entry : symbolMapping.asMap().entrySet()) { builder.put(entry.getKey(), Iterables.get(entry.getValue(), sourceIndex).toQualifiedNameReference()); } return builder.build(); }
private static Map<Symbol, QualifiedNameReference> extractExchangeOutputToInput(ExchangeNode exchange, int sourceIndex) { Map<Symbol, QualifiedNameReference> outputToInputMap = new HashMap<>(); for (int i = 0; i < exchange.getOutputSymbols().size(); i++) { outputToInputMap.put(exchange.getOutputSymbols().get(i), exchange.getInputs().get(sourceIndex).get(i).toQualifiedNameReference()); } return outputToInputMap; }
@Override public Expression visitExchange(ExchangeNode node, Void context) { return deriveCommonPredicates(node, source -> { Map<Symbol, QualifiedNameReference> mappings = new HashMap<>(); for (int i = 0; i < node.getInputs().get(source).size(); i++) { mappings.put( node.getOutputSymbols().get(i), node.getInputs().get(source).get(i).toQualifiedNameReference()); } return mappings.entrySet(); }); }
@Override public PlanNode visitExchange(ExchangeNode node, RewriteContext<Expression> context) { boolean modified = false; ImmutableList.Builder<PlanNode> builder = ImmutableList.builder(); for (int i = 0; i < node.getSources().size(); i++) { Map<Symbol, QualifiedNameReference> outputsToInputs = new HashMap<>(); for (int index = 0; index < node.getInputs().get(i).size(); index++) { outputsToInputs.put( node.getOutputSymbols().get(index), node.getInputs().get(i).get(index).toQualifiedNameReference()); } Expression sourcePredicate = ExpressionTreeRewriter.rewriteWith(new ExpressionSymbolInliner(outputsToInputs), 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 ExchangeNode( node.getId(), node.getType(), node.getPartitionFunction(), builder.build(), node.getInputs()); } return node; }
@Override public PlanNode visitEnforceSingleRow(EnforceSingleRowNode node, RewriteContext<Void> context) { PlanNode child = context.rewrite(node.getSource(), null); if (!child.getOutputSymbols().equals(node.getSource().getOutputSymbols())) { // Add a projection to remove extraneous hash output columns, // since EnforceSingleRow doesn't support them ImmutableMap.Builder<Symbol, Expression> assignments = ImmutableMap.builder(); for (Symbol symbol : node.getSource().getOutputSymbols()) { assignments.put(symbol, symbol.toQualifiedNameReference()); } child = new ProjectNode(idAllocator.getNextId(), child, assignments.build()); } return new EnforceSingleRowNode(node.getId(), child); }
projections.put(exchange.getPartitionFunction().getHashColumn().get(), exchange.getPartitionFunction().getHashColumn().get().toQualifiedNameReference()); inputs.add(exchange.getPartitionFunction().getHashColumn().get());
assignments.put(output, plan.getSymbol(index).toQualifiedNameReference());