{
PlanNode source = planRewriter.rewrite(node.getSource(), context);
if (node.getOutputSymbols().size() != source.getOutputSymbols().size()) {
// Can't get rid of this projection. It constrains the output tuple from the underlying operator
return new ProjectNode(node.getId(), source, node.getOutputMap());
}
boolean canElide = true;
for (Map.Entry<Symbol, Expression> entry : node.getOutputMap().entrySet()) {
Expression expression = entry.getValue();
Symbol symbol = entry.getKey();
if (!(expression instanceof QualifiedNameReference && ((QualifiedNameReference) expression).getName().equals(symbol.toQualifiedName()))) {
canElide = false;
break;
}
}
if (canElide) {
return source;
}
return new ProjectNode(node.getId(), source, node.getOutputMap());
}