You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/01/07 08:12:38 UTC

[GitHub] [calcite] danny0405 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

danny0405 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_r363631241
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java
 ##########
 @@ -227,8 +227,13 @@ public Result visit(Project e) {
     if (isStar(e.getChildExps(), e.getInput().getRowType(), e.getRowType())) {
       return x;
     }
-    final Builder builder =
-        x.builder(e, Clause.SELECT);
+    final Builder builder;
+    if (e.getInput() instanceof Sort) {
+      builder = x.builder(e);
+      builder.clauses.add(Clause.SELECT);
+    } else {
 
 Review comment:
   With this change, i believe that code snippet in `visit(Sort)` can be removed:
   
   ```java
   if (stack.size() != 1 && builder.select.getSelectList() == null) {
         // Generates explicit column names instead of start(*) for
         // non-root order by to avoid ambiguity.
         final List<SqlNode> selectList = Expressions.list();
         for (RelDataTypeField field : e.getRowType().getFieldList()) {
           addSelect(selectList, builder.context.field(field.getIndex()), e.getRowType());
         }
         builder.select.setSelectList(new SqlNodeList(selectList, POS));
       }
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services