ehds commented on code in PR #5130:
URL: https://github.com/apache/calcite/pull/5130#discussion_r3670671032
##########
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java:
##########
@@ -194,6 +194,8 @@ protected SqlImplementor(SqlDialect dialect) {
public final Result visitRoot(RelNode r) {
List<RelOptRule> rules = new ArrayList<>();
if (!this.dialect.supportsGroupByLiteral()) {
+ rules.add(CoreRules.PROJECT_MERGE);
Review Comment:
I added a new UT to explain why we need theses two rules.
For this sql:
```SQL
SELECT id, employee_id
FROM (
SELECT id, employee_id
FROM (
SELECT employee_id, NULL AS id
FROM employee
) AS t1
) AS t2
GROUP BY id, employee_id
```
It will be transformed to:
```SQL
LogicalAggregate(group=[{0, 1}])
LogicalProject(id=[$1], employee_id=[$0])
LogicalProject(employee_id=[$0], id=[null:NULL])
JdbcTableScan(table=[[foodmart, employee]])
```
`AggregateProjectConstantToDummyJoinRule` (added by
[CALCITE-4702](https://issues.apache.org/jira/browse/CALCITE-4702)) only
matches the `Agg->Project` pattern, however, `$1` and `$0` are not literals, so
the rule does not fire.
To fix it, we should remove unnecessary PROJECT operations by these two
rules.
Or if you have a better suggestion, I'll follow up.
--
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]