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 2022/10/13 05:53:48 UTC

[GitHub] [calcite] JiajunBernoulli commented on a diff in pull request #2931: [CALCITE-5248] Support extended column aliasing in select list and where, on and filter clauses

JiajunBernoulli commented on code in PR #2931:
URL: https://github.com/apache/calcite/pull/2931#discussion_r994176618


##########
core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java:
##########
@@ -2815,6 +2815,45 @@ private SqlDialect nonOrdinalDialect() {
     sql(query).ok(expected);
   }
 
+  @Test public void testSelectQueryAliasInWhereClause() {
+    String query = "select  \"cases_per_pallet\" as c from \"product\" where c > 100 ";
+    final String expected = "SELECT \"cases_per_pallet\" AS \"C\"\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "WHERE \"cases_per_pallet\" > 100";
+    sql(query).ok(expected);
+  }
+
+
+  @Test public void testSelectQueryAliasInSelectList() {
+    String query = "select  \"cases_per_pallet\" as c, upper(c) from \"product\" ORDER BY c";
+    final String expected = "SELECT \"cases_per_pallet\" AS \"C\", UPPER(CAST"
+        + "(\"cases_per_pallet\" AS VARCHAR CHARACTER SET \"ISO-8859-1\"))\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "ORDER BY \"cases_per_pallet\"";
+    sql(query).ok(expected);
+  }
+
+  @Test public void testSelectQueryAliasInOn() {
+    String query = "select  \"employee_id\" as c, \"product_id\" p from \"product\" "
+            +" JOIN \"employee\" "+
+            " ON c = p ";
+    final String expected = "SELECT \"employee\".\"employee_id\" AS \"C\", \"product\".\"product_id\" AS \"P\""+
+          "FROM \"foodmart\".\"product\"" +
+          "INNER JOIN \"foodmart\".\"employee\" ON \"product\".\"product_id\" = \"employee\".\"employee_id\"";
+    sql(query).ok(expected);
+  }
+
+  @Test public void testSelectQueryAliasPreferenceForInnerSubQuery() {
+    String query = "select  \"employee_id\" as c, lower(c) from "
+            + "( SELECT \"employee_id\", \"gender\" AS c " +
+           "FROM \"employee\")";
+
+    final String expected = "SELECT \"employee_id\" AS \"C\", LOWER(\"gender\")\nFROM \"foodmart\".\"employee\"";
+    sql(query).ok(expected);
+  }
+

Review Comment:
   Calcite support group by alias, would you please add some unit test that alias be used by aggregate and filter?



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

To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org