SubPlanBuilder current = node.getSource().accept(this, context);
// use partial TopN plan if distributed
boolean partial = current.isDistributed();
current.setRoot(new TopNNode(node.getId(), current.getRoot(), node.getCount(), node.getOrderBy(), node.getOrderings(), partial, node.getSampleWeight()));
if (current.isDistributed()) {
current.setRoot(new SinkNode(idAllocator.getNextId(), current.getRoot(), current.getRoot().getOutputSymbols()));
// create merge plan fragment
PlanNode source = new ExchangeNode(idAllocator.getNextId(), current.getId(), current.getRoot().getOutputSymbols());
TopNNode merge = new TopNNode(idAllocator.getNextId(), source, node.getCount(), node.getOrderBy(), node.getOrderings(), false, node.getSampleWeight());
current = createSingleNodePlan(merge)
.addChild(current.build());
}
return current;