@Override
public SubPlanBuilder visitLimit(LimitNode node, Void context)
{
SubPlanBuilder current = node.getSource().accept(this, context);
current.setRoot(new LimitNode(node.getId(), current.getRoot(), node.getCount(), 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());
LimitNode merge = new LimitNode(idAllocator.getNextId(), source, node.getCount(), node.getSampleWeight());
current = createSingleNodePlan(merge)
.addChild(current.build());
}
return current;