[ https://issues.apache.org/jira/browse/CALCITE-2143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16334450#comment-16334450 ]
Samuel Waggoner commented on CALCITE-2143: ------------------------------------------ PR here. As I note in the comments, I don't think this solution is very elegant, but wanted to get a maintainer's eyes on it. https://github.com/apache/calcite/pull/613 > RelToSqlConverter produces incorrect SQL with aggregation > --------------------------------------------------------- > > Key: CALCITE-2143 > URL: https://issues.apache.org/jira/browse/CALCITE-2143 > Project: Calcite > Issue Type: Bug > Affects Versions: 1.15.0 > Reporter: Austin Haas > Assignee: Julian Hyde > Priority: Major > > This plan: > {code:java} > LogicalAggregate(group=[{1}], my-alias=[SUM($0)]) > LogicalAggregate(group=[{0, 1}]) > LogicalProject(b=[$2], a=[$0]) > LogicalJoin(condition=[=($0, $1)], joinType=[inner]) > LogicalTableScan(table=[[rel-1]]) > LogicalTableScan(table=[[rel-2]]){code} > Produces this erroneous SQL: > {code:sql} > SELECT `t0`.`my-alias` AS `a`, (SUM(`t0`.`a`)) AS `my-alias` > FROM (SELECT `rel-2`.`b`, `rel-1`.`a` > FROM `rel-1` > INNER JOIN `rel-2` ON (`rel-1`.`a` = `rel-2`.`a`) > GROUP BY `rel-2`.`b`, `rel-1`.`a`) AS `t0` > GROUP BY `t0`.`my-alias`{code} > Note the first field of the outer SELECT, where 'my-alias' is aliased as 'a'. > Any clues how to fix would be appreciated. -- This message was sent by Atlassian JIRA (v7.6.3#76005)