This is an automated email from the ASF dual-hosted git repository.
xuzifu666 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new a8345ae8ea [CALCITE-7533] Parser rejects parenthesized query as the
body of a WITH clause
a8345ae8ea is described below
commit a8345ae8ea8ba951d2663db0cf9637f5884db37b
Author: Darpan <[email protected]>
AuthorDate: Tue May 19 10:15:11 2026 +0530
[CALCITE-7533] Parser rejects parenthesized query as the body of a WITH
clause
---
core/src/main/codegen/templates/Parser.jj | 8 ++++++--
.../org/apache/calcite/sql/parser/SqlParserTest.java | 16 ++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/core/src/main/codegen/templates/Parser.jj
b/core/src/main/codegen/templates/Parser.jj
index b89ca5c5f5..2f784b3412 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -3715,8 +3715,12 @@ SqlNode Query(ExprContext exprContext) :
final List<Object> list = new ArrayList<Object>();
}
{
- [ withList = WithList() ]
- e = LeafQuery(exprContext) { list.add(e); }
+ (
+ withList = WithList()
+ e = LeafQueryOrExpr(exprContext) { list.add(e); }
+ |
+ e = LeafQuery(exprContext) { list.add(e); }
+ )
( AddSetOpQuery(list, exprContext) )*
{ return addWith(withList, SqlParserUtil.toTree(list)); }
}
diff --git
a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
index 955f268cc5..4ab6f776ba 100644
--- a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -2826,6 +2826,22 @@ void checkPeriodPredicate(Checker checker) {
sql(sql).ok(expected);
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7533">[CALCITE-7533]
+ * Parser rejects parenthesized query as the body of a WITH clause</a>. */
+ @Test void testWithParenthesizedBody() {
+ final String sql = "select * from (\n"
+ + " with q as (select 1 as id)\n"
+ + " (select id from q) union all (select id from q)) t";
+ final String expected = "SELECT *\n"
+ + "FROM (WITH `Q` AS (SELECT 1 AS `ID`) SELECT `ID`\n"
+ + "FROM `Q`\n"
+ + "UNION ALL\n"
+ + "SELECT `ID`\n"
+ + "FROM `Q`) AS `T`";
+ sql(sql).ok(expected);
+ }
+
/** Test case for
* <a
href="https://issues.apache.org/jira/browse/CALCITE-5252">[CALCITE-5252]
* JDBC adapter sometimes miss parentheses around SELECT in WITH_ITEM
body</a>. */