helloppx commented on issue #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#issuecomment-571927284
 
 
   > I add a test case in RelToSqlConverterTest, it seems to produce a correct 
sql
   > 
   > ```
   > @Test public void testGroupByWithLimitPlan() {
   >     String query = "SELECT sum(\"salary\") FROM \"employee\" group by 
\"gender\" limit 10";
   >     sql(query)
   >         .ok("SELECT SUM(\"salary\")\n"
   >             + "FROM \"foodmart\".\"employee\"\n"
   >             + "GROUP BY \"gender\"\n"
   >             + "FETCH NEXT 10 ROWS ONLY");
   >   }
   > ```
   
   Hi @yanlin-Lynn @danny0405 
   If we want to reproduce this JIRA case we need to make sure `Sort` is input 
of `Project` [1].
   If we move the case to `RelToSqlConverterTest`, it will produce a plan [2] 
so we cannot reproduce the JIRA case.
   
   [1]
   ```
   JdbcToEnumerableConverter
     JdbcProject(EXPR$0=[$1])
       JdbcSort(fetch=[10])
         JdbcAggregate(group=[{1}], EXPR$0=[SUM($5)])
           JdbcTableScan(table=[[SCOTT, EMP]])
   ```
   [2]
   ```
   LogicalSort(fetch=[10])
     LogicalProject(EXPR$0=[$1])
       LogicalAggregate(group=[{0}], EXPR$0=[SUM($1)])
         LogicalProject(brand_name=[$2], net_weight=[$7])
           JdbcTableScan(table=[[foodmart, product]])
   ```

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

Reply via email to