if (debug.val)
LOG.debug("SKIP - Does not contain any ReceivePlanNodes");
return (Pair.of(false, root));
}
OrderByPlanNode orderby_node = null;
LimitPlanNode limit_node = null;
try {
// If there is an OrderByPlanNode, then that we need to clone that too.
if (orderby_nodes.size() != 0) {
orderby_node = (OrderByPlanNode) CollectionUtil.first(orderby_nodes).clone(false, true);
assert (orderby_node != null);
}
limit_node = (LimitPlanNode) CollectionUtil.first(limit_nodes).clone(false, true);
} catch (CloneNotSupportedException ex) {
throw new RuntimeException(ex);
}
assert (limit_node != null);
if (debug.val) {
LOG.debug("LIMIT: " + PlanNodeUtil.debug(limit_node));
LOG.debug("ORDER BY: " + PlanNodeUtil.debug(orderby_node));
LOG.debug(PlanNodeUtil.getPlanNodes(root, AbstractScanPlanNode.class));
}
AbstractScanPlanNode scan_node = CollectionUtil.first(PlanNodeUtil.getPlanNodes(root, AbstractScanPlanNode.class));
assert (scan_node != null) : "Unexpected PlanTree:\n" + PlanNodeUtil.debug(root);
SendPlanNode send_node = (SendPlanNode) scan_node.getParent(0);
assert (send_node != null);
send_node.addIntermediary(limit_node);
if (orderby_node != null) {
limit_node.addIntermediary(orderby_node);
// Need to make sure that the LIMIT has the proper output columns
limit_node.setOutputColumns(orderby_node.getOutputColumnGUIDs());
state.markDirty(orderby_node);
} else {
// Need to make sure that the LIMIT has the proper output columns
limit_node.setOutputColumns(scan_node.getOutputColumnGUIDs());
}