Skip to content

Commit eff89a5

Browse files
authored
Merge pull request #1153 from zhicwu/develop
Fix issue of parsing insert with settings
2 parents 925fde5 + 55061ae commit eff89a5

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

clickhouse-jdbc/src/main/javacc/ClickHouseSqlParser.jj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ void insertStmt(): {} {
512512
LOOKAHEAD({ getToken(1).kind == FUNCTION }) <FUNCTION> functionExpr()
513513
| (LOOKAHEAD(2) <TABLE>)? tableIdentifier(true)
514514
)
515+
( settingsPart() )?
515516
dataClause()
516517
}
517518

@@ -528,7 +529,6 @@ void dataClause(): {} {
528529
columnExprList()
529530
<RPAREN> { token_source.removePosition(ClickHouseSqlStatement.KEYWORD_VALUES_END); }
530531
)*
531-
( settingsPart() )?
532532
| (LOOKAHEAD(2) ((withClause())? <SELECT> { token_source.addPosition(token); } columnExprList() <FROM>
533533
<INPUT> <LPAREN> <STRING_LITERAL> { token_source.input = ClickHouseSqlUtils.unescape(token.image); } <RPAREN>)?
534534
<FORMAT> <IDENTIFIER> { token_source.format = token.image; } )? (anyExprList())?

clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import com.clickhouse.client.config.ClickHouseClientOption;
4343
import com.clickhouse.client.data.ClickHouseBitmap;
4444
import com.clickhouse.client.data.ClickHouseExternalTable;
45-
import com.clickhouse.client.data.UnsignedByte;
4645
import com.clickhouse.client.data.UnsignedInteger;
4746
import com.clickhouse.client.data.UnsignedLong;
4847
import com.clickhouse.jdbc.internal.InputBasedPreparedStatement;
@@ -1580,6 +1579,33 @@ public void testInsertWithNullDateTime() throws SQLException {
15801579
}
15811580
}
15821581

1582+
@Test(groups = "integration")
1583+
public void testInsertWithSettings() throws SQLException {
1584+
Properties props = new Properties();
1585+
try (ClickHouseConnection conn = newConnection(props); Statement s = conn.createStatement()) {
1586+
if (!conn.getServerVersion().check("[22.5,)")) {
1587+
throw new SkipException(
1588+
"Skip due to breaking change introduced by https://github.com/ClickHouse/ClickHouse/pull/35883");
1589+
}
1590+
1591+
s.execute("drop table if exists test_insert_with_settings; "
1592+
+ "CREATE TABLE test_insert_with_settings(i Int32, s String) ENGINE=Memory");
1593+
try (PreparedStatement ps = conn
1594+
.prepareStatement(
1595+
"INSERT INTO test_insert_with_settings SETTINGS async_insert=1,wait_for_async_insert=1 values(?, ?)")) {
1596+
ps.setInt(1, 1);
1597+
ps.setString(2, "1");
1598+
ps.addBatch();
1599+
ps.executeBatch();
1600+
}
1601+
1602+
try (ResultSet rs = s.executeQuery("select * from test_insert_with_settings order by i")) {
1603+
Assert.assertTrue(rs.next());
1604+
Assert.assertFalse(rs.next());
1605+
}
1606+
}
1607+
}
1608+
15831609
@Test(groups = "integration")
15841610
public void testGetParameterMetaData() throws SQLException {
15851611
try (Connection conn = newConnection(new Properties());

clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/parser/ClickHouseSqlParserTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,10 @@ public void testInsertStatement() throws ParseException {
238238
checkSingleStatement(parse(sql = "INSERT INTO insert_select_testtable (* EXCEPT(b)) Values (2, 2)"),
239239
sql, StatementType.INSERT, "system", "insert_select_testtable");
240240
checkSingleStatement(
241-
parse(sql = "insert into `test` (num) values (?) SETTINGS input_format_null_as_default = 1"),
241+
parse(sql = "insert into `test` (num)SETTINGS input_format_null_as_default = 1 values (?)"),
242242
sql, StatementType.INSERT, "system", "test");
243243
checkSingleStatement(
244-
parse(sql = "insert into `test` (id, name) values (1,2)(3,4),(5,6) SETTINGS input_format_null_as_default = 1"),
244+
parse(sql = "insert into `test` (id, name) SETTINGS input_format_null_as_default = 1 values (1,2)(3,4),(5,6)"),
245245
sql, StatementType.INSERT, "system", "test");
246246
s = checkSingleStatement(
247247
parse(sql = "insert into `test`"), sql, StatementType.INSERT, "system", "test");

0 commit comments

Comments
 (0)