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/03/04 03:09:36 UTC

[GitHub] [calcite] NobiGo commented on a change in pull request #2724: [CACLITE-5013] Retain parentheses if a setop has an LIMIT clause

NobiGo commented on a change in pull request #2724:
URL: https://github.com/apache/calcite/pull/2724#discussion_r819230289



##########
File path: core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
##########
@@ -3301,6 +3301,71 @@ private void checkHavingAliasSameAsColumn(boolean upperAlias) {
     sql(query).ok(expected);
   }
 
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-5013">[CALCITE-5013]
+   * Unparse SqlSetOperator should be retained parentheses
+   * when the operand has limit or offset</a>. */
+  @Test void testSetOpRetainParentheses() {
+    // Parentheses will be discarded, because semantics not be affected.
+    final String discardedParenthesesQuery = "SELECT \"product_id\" FROM \"product\""
+        + "UNION ALL\n"
+        + "(SELECT \"product_id\" FROM \"product\" WHERE \"product_id\" > 10)\n"
+        + "INTERSECT ALL\n"
+        + "(SELECT \"product_id\" FROM \"product\" )";
+    final String discardedParenthesesRes = "SELECT \"product_id\"\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "UNION ALL\n"
+        + "SELECT *\n"
+        + "FROM (SELECT \"product_id\"\n"
+        + "FROM \"foodmart\".\"product\"\n"
+        + "WHERE \"product_id\" > 10\n"
+        + "INTERSECT ALL\n"
+        + "SELECT \"product_id\"\n"
+        + "FROM \"foodmart\".\"product\")";
+    sql(discardedParenthesesQuery).ok(discardedParenthesesRes);
+
+    // Parentheses will be retained because subquery has limit or offset.
+    // If parentheses  are discarded the semantics of parsing will be affected.

Review comment:
       redundant blank space after the parentheses

##########
File path: core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
##########
@@ -3301,6 +3301,71 @@ private void checkHavingAliasSameAsColumn(boolean upperAlias) {
     sql(query).ok(expected);
   }
 
+
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-5013">[CALCITE-5013]
+   * Unparse SqlSetOperator should be retained parentheses
+   * when the operand has limit or offset</a>. */
+  @Test void testSetOpRetainParentheses() {

Review comment:
       I'm suspect whether we should remove the parentheses?
   If the SQL is :
   ```
   "SELECT \"product_id\" FROM \"product\""
           + "UNION ALL\n"
           + "(SELECT \"product_id\" FROM \"product\")\n"
           + "INTERSECT ALL\n"
           + "(SELECT \"product_id\" FROM \"product\" WHERE \"product_id\" > 10)"
   ```
   ```
   SELECT \"product_id\"
   FROM \"foodmart\".\"product\"
   UNION ALL
   SELECT *
   FROM (SELECT \"product_id\"
   FROM \"foodmart\".\"product\"
   INTERSECT ALL
   SELECT \"product_id\"
   FROM \"foodmart\".\"product\"
   WHERE \"product_id\" > 10)
   ```
   
   I think it has become unclear? So maybe we should stay the parentheses?
   




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