libenchao commented on code in PR #3052:
URL: https://github.com/apache/calcite/pull/3052#discussion_r1184848806
##########
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java:
##########
@@ -1831,6 +1831,21 @@ && hasSortByOrdinal()) {
return true;
}
+ if (rel instanceof Project) {
+ Project project = (Project) rel;
+ RelNode input = project.getInput();
+ // Cannot merge because "select 1 from t"
+ // is different from "select 1 from (select count(1) from t)"
+ final boolean hasInputRef = project.getProjects()
+ .stream()
+ .anyMatch(rex -> RexUtil.containsInputRef(rex));
+ final boolean hasAggregate =
+ input instanceof Aggregate && input.getRowType().getFieldCount() >
0;
Review Comment:
Sorry that I misunderstood the attention of this condition. Now I think I
get your point, and it looks correct (although it may be a little coarse
grained, it's ok to me because we have `hasInputRef` to narrow down the impact)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]