Skip to content

Commit 3dbcdb9

Browse files
authored
Merge pull request #2135 from samssh/fix#2132
fix: #2132 fix executing queries with 'WITH' clause in jdbc v2
2 parents 44cb5f9 + 7c507b1 commit 3dbcdb9

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ protected static StatementType parseStatementType(String sql) {
8484

8585
switch (tokens[0].toUpperCase()) {
8686
case "SELECT": return StatementType.SELECT;
87+
case "WITH": return StatementType.SELECT;
8788
case "INSERT": return StatementType.INSERT;
8889
case "DELETE": return StatementType.DELETE;
8990
case "UPDATE": return StatementType.UPDATE;

jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,20 @@ public void testEscapeStrings() throws Exception {
260260
}
261261
}
262262
}
263+
264+
265+
@Test(groups = "integration")
266+
void testWithClause() throws Exception {
267+
int count = 0;
268+
try (Connection conn = getJdbcConnection()) {
269+
try (PreparedStatement stmt = conn.prepareStatement("with data as (SELECT number FROM numbers(100)) select * from data ")) {
270+
stmt.execute();
271+
ResultSet rs = stmt.getResultSet();
272+
while (rs.next()) {
273+
count++;
274+
}
275+
}
276+
}
277+
assertEquals(count, 100);
278+
}
263279
}

jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ public void testWithComments() throws Exception {
464464
assertEquals(StatementImpl.parseStatementType(" "), StatementImpl.StatementType.OTHER);
465465
}
466466

467+
@Test(groups = { "integration" })
468+
public void testParseStatementWithClause() throws Exception {
469+
assertEquals(StatementImpl.parseStatementType("with data as (SELECT number FROM numbers(100)) select * from data"), StatementImpl.StatementType.SELECT);
470+
}
471+
467472

468473
@Test(groups = { "integration" })
469474
public void testWithIPs() throws Exception {
@@ -539,4 +544,19 @@ public void testTextFormatInResponse() throws Exception {
539544
Assert.expectThrows(SQLException.class, () ->stmt.executeQuery("SELECT 1 FORMAT JSON"));
540545
}
541546
}
547+
548+
@Test(groups = "integration")
549+
void testWithClause() throws Exception {
550+
int count = 0;
551+
try (Connection conn = getJdbcConnection()) {
552+
try (Statement stmt = conn.createStatement()) {
553+
stmt.execute("with data as (SELECT number FROM numbers(100)) select * from data");
554+
ResultSet rs = stmt.getResultSet();
555+
while (rs.next()) {
556+
count++;
557+
}
558+
}
559+
}
560+
assertEquals(count, 100);
561+
}
542562
}

0 commit comments

Comments
 (0)