Skip to content

Commit 957fce5

Browse files
committed
fixed CTE wrapped with parenthesis
1 parent fbc2248 commit 957fce5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

jdbc-v2/src/main/antlr4/com/clickhouse/jdbc/internal/ClickHouseParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ query
4040

4141
// CTE statement
4242
ctes
43-
: WITH namedQuery (',' namedQuery)*
43+
: LPAREN? WITH namedQuery (',' namedQuery)* RPAREN?
4444
;
4545

4646
namedQuery

jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/SqlParserTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,24 @@ public static Object[][] testCreateStmtDP() {
241241
{"CREATE USER 'user01' IDENTIFIED BY 'qwerty'"},
242242
};
243243
}
244+
245+
@Test(dataProvider = "testCTEStmtsDP")
246+
public void testCTEStatements(String sql, int args) {
247+
SqlParser parser = new SqlParser();
248+
ParsedPreparedStatement stmt = parser.parsePreparedStatement(sql);
249+
Assert.assertFalse(stmt.isHasErrors());
250+
Assert.assertEquals(stmt.getArgCount(), args);
251+
}
252+
253+
@DataProvider
254+
public static Object[][] testCTEStmtsDP() {
255+
return new Object[][] {
256+
{"with ? as a, ? as b select a, b; -- two CTEs of the first form", 2},
257+
{"with a as (select ?), b as (select 2) select * from a, b; -- two CTEs of the second form", 1},
258+
{"(with a as (select ?) select * from a);", 1},
259+
{"with a as (select 1) select * from a; ", 0},
260+
{"(with ? as a select a);", 1},
261+
262+
};
263+
}
244264
}

0 commit comments

Comments
 (0)