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_r363573662
 
 

 ##########
 File path: core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java
 ##########
 @@ -177,6 +177,38 @@
             + "ON \"t\".\"DEPTNO\" = \"t0\".\"DEPTNO\"");
   }
 
+  @Test public void testGroupByWithLimitPlan() {
+    CalciteAssert.model(JdbcTest.SCOTT_MODEL)
+        .query("select sum(sal)\n"
+            + "from scott.emp \n"
+            + "group by ename limit 10")
+        .planHasSql("SELECT SUM(\"SAL\")\n"
+            + "FROM \"SCOTT\".\"EMP\"\n"
+            + "GROUP BY \"ENAME\"\n"
+            + "LIMIT 10");
+  }
+
+  @Test public void testSelectImplicitAliasByStar() {
+    CalciteAssert.model(JdbcTest.FOODMART_MODEL)
+        .query(
+            "select \"product_id\" + 1, * from ("
+            + "select * from\n"
+            + "("
+            + "select \"product_id\", sum(\"store_sales\") from 
\"sales_fact_1997\" group by \"product_id\") A\n"
+            + "union all\n"
+            + "select * from (\n"
+            + "select \"product_id\", sum(\"store_sales\") from 
\"sales_fact_1997\" group by \"product_id\") B\n"
+            + ") C")
+        .planHasSql("SELECT \"product_id\" + 1, \"product_id\", \"EXPR$1\"\n" +
+            "FROM (SELECT \"product_id\", COALESCE(SUM(\"store_sales\"), 0) AS 
\"EXPR$1\"\n" +
+            "FROM \"foodmart\".\"sales_fact_1997\"\n" +
+            "GROUP BY \"product_id\"\n" +
+            "UNION ALL\n" +
+            "SELECT \"product_id\", COALESCE(SUM(\"store_sales\"), 0) AS 
\"EXPR$1\"\n" +
+            "FROM \"foodmart\".\"sales_fact_1997\"\n" +
+            "GROUP BY \"product_id\") AS \"t1\"");
+  }
 
 Review comment:
   I tested that case and it seems right:  
   
   ```
   SELECT "shelf_width", "shelf_width" AS "shelf_width0", "EXPR$1"
   FROM (SELECT "shelf_width", "product_id" + 1 AS "EXPR$1"
   FROM "foodmart"."product"
   UNION ALL 
   SELECT "shelf_width", "product_id"
   FROM "foodmart"."product") AS "t1"
   ```

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