@Override public Void visitExchange(ExchangeNode node, Void context) { List<PartitionFunctionArgumentBinding> symbols = node.getOutputSymbols().stream() .map(PartitionFunctionArgumentBinding::new) .collect(toImmutableList()); if (node.getType() == REPARTITION) { symbols = node.getPartitionFunction().getPartitionFunctionArguments(); } String columns = Joiner.on(", ").join(symbols); printNode(node, format("ExchangeNode[%s]", node.getType()), columns, NODE_COLORS.get(NodeType.EXCHANGE)); for (PlanNode planNode : node.getSources()) { planNode.accept(this, context); } return null; }
exchange.getPartitionFunction().getPartitionFunctionArguments().stream() .filter(PartitionFunctionArgumentBinding::isVariable) .map(PartitionFunctionArgumentBinding::getColumn) }); if (exchange.getPartitionFunction().getHashColumn().isPresent()) { projections.put(exchange.getPartitionFunction().getHashColumn().get(), exchange.getPartitionFunction().getHashColumn().get().toQualifiedNameReference()); inputs.add(exchange.getPartitionFunction().getHashColumn().get()); exchange.getPartitionFunction().getPartitionFunctionArguments().stream() .filter(PartitionFunctionArgumentBinding::isVariable) .map(PartitionFunctionArgumentBinding::getColumn) .forEach(outputBuilder::add); if (exchange.getPartitionFunction().getHashColumn().isPresent()) { outputBuilder.add(exchange.getPartitionFunction().getHashColumn().get()); exchange.getPartitionFunction().getPartitioningHandle(), outputBuilder.build(), exchange.getPartitionFunction().getPartitionFunctionArguments(), exchange.getPartitionFunction().getHashColumn(), exchange.getPartitionFunction().isReplicateNulls(), exchange.getPartitionFunction().getBucketToPartition());
node.getPartitionFunction().getHashColumn().ifPresent(expectedOutputSymbols::add); node.getPartitionFunction().getPartitionFunctionArguments().stream() .filter(PartitionFunctionArgumentBinding::isVariable) .map(PartitionFunctionArgumentBinding::getColumn) node.getPartitionFunction().getPartitioningHandle(), newOutputSymbols, node.getPartitionFunction().getPartitionFunctionArguments(), node.getPartitionFunction().getHashColumn(), node.getPartitionFunction().isReplicateNulls(), node.getPartitionFunction().getBucketToPartition());
node.getPartitionFunction().getPartitioningHandle(), outputs.build(), canonicalizePartitionFunctionArgument(node.getPartitionFunction().getPartitionFunctionArguments()), canonicalize(node.getPartitionFunction().getHashColumn()), node.getPartitionFunction().isReplicateNulls(), node.getPartitionFunction().getBucketToPartition());
@Override public PlanNode visitExchange(ExchangeNode node, List<PlanNode> newChildren) { return new ExchangeNode( node.getId(), node.getType(), node.getPartitionFunction(), newChildren, node.getInputs()); }
@Override public Void visitExchange(ExchangeNode node, Void context) { for (int i = 0; i < node.getSources().size(); i++) { PlanNode subplan = node.getSources().get(i); checkDependencies(subplan.getOutputSymbols(), node.getInputs().get(i), "EXCHANGE subplan must provide all of the necessary symbols"); checkDependencies(subplan.getOutputSymbols(), node.getInputs().get(i), "EXCHANGE subplan must provide all of the necessary symbols"); subplan.accept(this, context); // visit child } checkDependencies(node.getOutputSymbols(), node.getPartitionFunction().getOutputLayout(), "EXCHANGE must provide all of the necessary symbols for partition function"); verifyUniqueId(node); return null; }
@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; }
return ActualProperties.builder() .global(partitionedOn( node.getPartitionFunction().getPartitioningHandle(), node.getPartitionFunction().getPartitionFunctionArguments(), Optional.of(node.getPartitionFunction().getPartitionFunctionArguments()))) .constants(constants) .build();
@Override public PlanNode visitExchange(ExchangeNode exchange, RewriteContext<FragmentProperties> context) { PartitionFunctionBinding partitionFunction = exchange.getPartitionFunction(); ImmutableList.Builder<SubPlan> builder = ImmutableList.builder(); if (exchange.getType() == ExchangeNode.Type.GATHER) { context.get().setSingleNodeDistribution(); for (int i = 0; i < exchange.getSources().size(); i++) { FragmentProperties childProperties = new FragmentProperties(partitionFunction.translateOutputLayout(exchange.getInputs().get(i))); builder.add(buildSubPlan(exchange.getSources().get(i), childProperties, context)); } } else if (exchange.getType() == ExchangeNode.Type.REPARTITION) { context.get().setDistribution(partitionFunction.getPartitioningHandle()); FragmentProperties childProperties = new FragmentProperties(partitionFunction.translateOutputLayout(Iterables.getOnlyElement(exchange.getInputs()))); builder.add(buildSubPlan(Iterables.getOnlyElement(exchange.getSources()), childProperties, context)); } else if (exchange.getType() == ExchangeNode.Type.REPLICATE) { FragmentProperties childProperties = new FragmentProperties(partitionFunction.translateOutputLayout(Iterables.getOnlyElement(exchange.getInputs()))); builder.add(buildSubPlan(Iterables.getOnlyElement(exchange.getSources()), childProperties, context)); } List<SubPlan> children = builder.build(); context.get().addChildren(children); List<PlanFragmentId> childrenIds = children.stream() .map(SubPlan::getFragment) .map(PlanFragment::getId) .collect(toImmutableList()); return new RemoteSourceNode(exchange.getId(), childrenIds, exchange.getOutputSymbols()); }