ehds commented on code in PR #5130:
URL: https://github.com/apache/calcite/pull/5130#discussion_r3671282579
##########
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:
Indeed, this current solution only handles particular cases.
I think a more general fix would be to wrap the input in a subquery when
determining `needNewSubQuery` if any GROUP BY expression contains a literal.
```
LogicalAggregate(group=[{0, 1}])
LogicalProject(id=[$1], employee_id=[$0])
LogicalProject(employee_id=[$0], id=[null:NULL])
JdbcTableScan(table=[[foodmart, employee]])
```
Translate this plan into the following SQL form:
```SQL
SELECT employee_id, id
FROM (SELECT employee_id, null as id from foodmart.employee) as t
group by t.employee_id, t.id
```
And this approach is similar to the fixes used for other cases,such as
[CALCITE-7655](https://issues.apache.org/jira/browse/CALCITE-7655),
[CALCITE-4491](https://issues.apache.org/jira/browse/CALCITE-4491)
--
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]