JiajunBernoulli commented on a change in pull request #2724:
URL: https://github.com/apache/calcite/pull/2724#discussion_r825255397
##########
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:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]