helloppx commented on a change in pull request #1715: [CALCITE-3662] Generate
wrong SQL when plan contains Project(Sort(Aggregate)) and aggregate field has
no alias
URL: https://github.com/apache/calcite/pull/1715#discussion_r364647262
##########
File path:
core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
##########
@@ -918,8 +913,16 @@ public Result visit(TableFunctionScan e) {
String alias = SqlValidatorUtil.getAlias(node, -1);
final String lowerName = name.toLowerCase(Locale.ROOT);
if (lowerName.startsWith("expr$")) {
- // Put it in ordinalMap
- ordinalMap.put(lowerName, node);
+ final ArrayDeque<Frame> clone = new ArrayDeque<>(stack);
+ clone.pop();
+ final Frame parent = clone.peek();
+ if (parent != null && parent.r instanceof Union) {
+ // For case: Project(Union(expression without alias))
Review comment:
Hi @danny0405 , I have updated the solution and fix the code conflict.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services