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/06 20:21:10 UTC

[GitHub] [calcite] jaystarshot opened a new pull request, #2931: [Calcite-5248] Support extended column aliasing in select list and where, on and filter clauses

jaystarshot opened a new pull request, #2931:
URL: https://github.com/apache/calcite/pull/2931

   Based on the ticket https://issues.apache.org/jira/browse/CALCITE-5248


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


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

Posted by GitBox <gi...@apache.org>.
jaystarshot commented on code in PR #2931:
URL: https://github.com/apache/calcite/pull/2931#discussion_r994622813


##########
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:
   Hi Jiajun, thanks for the review and I am adding an alias test for group by but there is some error with conformance. Apparently group by alias is only allowed with the conformance isGroupByAlias true which is true for bigquery, mysql etc but when I run in my PR, it does not seem to recognize that conformance



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


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

Posted by GitBox <gi...@apache.org>.
jaystarshot commented on code in PR #2931:
URL: https://github.com/apache/calcite/pull/2931#discussion_r994622813


##########
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:
   Hi Jianjun, thanks for the review and I have added a simple unit test where alias is used both in filter and aggregate



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


[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

Posted by GitBox <gi...@apache.org>.
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