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 be6f24a1e3 Test case for [CALCITE-5216] Cannot parse parenthesized 
nested WITH clause
be6f24a1e3 is described below

commit be6f24a1e325bbe76f320a84078e77e36bd3b1ac
Author: Yu Xu <[email protected]>
AuthorDate: Thu Jul 16 11:24:05 2026 +0800

    Test case for [CALCITE-5216] Cannot parse parenthesized nested WITH clause
---
 core/src/test/resources/sql/sub-query.iq                     | 12 ++++++++++++
 .../java/org/apache/calcite/sql/parser/SqlParserTest.java    | 10 ++++++++++
 2 files changed, 22 insertions(+)

diff --git a/core/src/test/resources/sql/sub-query.iq 
b/core/src/test/resources/sql/sub-query.iq
index 84f9aa5183..daa85b9653 100644
--- a/core/src/test/resources/sql/sub-query.iq
+++ b/core/src/test/resources/sql/sub-query.iq
@@ -937,6 +937,18 @@ where sal + 100 not in (
 !ok
 !}
 
+# [CALCITE-5216] Cannot parse parenthesized nested WITH clause
+# This sql program was validated in PostgreSQL
+with a as (with b as (select 1)(select 1)) select * from a;
++--------+
+| EXPR$0 |
++--------+
+|      1 |
++--------+
+(1 row)
+
+!ok
+
 # [CALCITE-356] AssertionError while translating query with WITH and 
correlated sub-query
 !if (use_old_decorr) {
 with t (a, b) as (select * from (values (1, 2)))
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 372cd1189d..59bd1a5d20 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
@@ -2858,6 +2858,16 @@ void checkPeriodPredicate(Checker checker) {
     sql(sql).ok(expected);
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-5216";>[CALCITE-5216]
+   * Cannot parse parenthesized nested WITH clause</a>. */
+  @Test void testNestedWithParenthesized() {
+    final String sql = "with a as (with b as (select 1)(select 1)) select * 
from a";
+    final String expected = "WITH `A` AS (WITH `B` AS (SELECT 1) SELECT 1) 
SELECT *\n"
+        + "FROM `A`";
+    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>. */

Reply via email to