}
} else {
return root;
}
List<SingleElementSymbol> childOutputCols = (List<SingleElementSymbol>) projectNode.getFirstChild().getProperty(Info.OUTPUT_COLS);
OrderBy orderBy = (OrderBy) node.getProperty(Info.SORT_ORDER);
List<SingleElementSymbol> orderByKeys = orderBy.getSortKeys();
for (SingleElementSymbol ss : orderByKeys) {
if(ss instanceof AliasSymbol) {
ss = ((AliasSymbol)ss).getSymbol();
}
if (ss instanceof ExpressionSymbol && !(ss instanceof AggregateSymbol)) {
ExpressionSymbol exprSymbol = (ExpressionSymbol)ss;
if (!exprSymbol.isDerivedExpression()) {
return root; //TODO: insert a new project node to handle this case
}
}
if (!childOutputCols.contains(ss)) {
return root;
}
}
NodeEditor.removeChildNode(projectNode.getParent(), projectNode);
if (parent != null && parent.getType() == NodeConstants.Types.TUPLE_LIMIT && parent.getParent() != null) {
parent.addAsParent(projectNode);
} else {
if (parent == null) {
root = projectNode;
}
if (parent != null && parent.getType() == NodeConstants.Types.TUPLE_LIMIT) {
if (root == parent) {
root = projectNode;
}
projectNode.addFirstChild(parent);
} else {
projectNode.addFirstChild(node);
}
}
List<SingleElementSymbol> orderByOutputSymbols = (List<SingleElementSymbol>) node.getProperty(Info.OUTPUT_COLS);
boolean unrelated = false;
if (node.hasBooleanProperty(Info.UNRELATED_SORT)) {
node.setProperty(Info.UNRELATED_SORT, false);
unrelated = true;
}
for (OrderByItem item : orderBy.getOrderByItems()) {
if (unrelated) {
//update sort order
int index = childOutputCols.indexOf(item.getSymbol());
item.setExpressionPosition(index);
}