Skip to content

Commit 5d4d7e4

Browse files
committed
removed hardcoded settings. Updated changelog
1 parent 28cf959 commit 5d4d7e4

6 files changed

Lines changed: 73 additions & 60 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
## 0.9.9
22

3+
### Breaking Changes
34

4-
### Bug Fixes
5-
- **[jdbc-v2]** Fixed issues with hardcoded `async_insert` settings in `ConnectionImpl`. Now it let override them. (https://github.com/ClickHouse/clickhouse-java/issues/2652, https://github.com/ClickHouse/clickhouse-java/issues/2825)
5+
- **[jdbc-v2]** Hardcoded server setting `async_insert=0` is removed as well as others. This is done to
6+
fix issue with overriding these settings and using client with read-only profiles. The change, first of all, makes
7+
driver behavior to follow default what is set on server side (note: starting ClickHouse 26.3 `async_insert` is on by default).
8+
In second, this fix changes what number of affected rows returned by method like `java.sql.Statement.executeUpdate(java.lang.String)`.
9+
Previously they return more accurate values because insert was synchronous, but in case of asynchronous insert it is not
10+
guaranteed anymore (see also https://github.com/ClickHouse/ClickHouse/issues/57768). Read more about asynchronous insert https://clickhouse.com/docs/optimize/asynchronous-inserts.
11+
(https://github.com/ClickHouse/clickhouse-java/issues/2652, https://github.com/ClickHouse/clickhouse-java/issues/2825)
612

713
## 0.9.8
814

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.clickhouse.client.api.Client;
44
import com.clickhouse.client.api.ClientConfigProperties;
55
import com.clickhouse.client.api.http.ClickHouseHttpProto;
6-
import com.clickhouse.client.api.internal.ServerSettings;
76
import com.clickhouse.data.ClickHouseDataType;
87
import com.clickhouse.jdbc.Driver;
98
import com.clickhouse.jdbc.DriverProperties;
@@ -75,7 +74,7 @@ public boolean isIgnoreUnsupportedRequests() {
7574

7675
/**
7776
* Parses URL to get property and target host.
78-
* Properties that are passed in the {@code info} parameter will override that are set in the {@code url}.
77+
* Properties that are passed in the {@code url} will override the {@code info} ones.
7978
* @param url - JDBC url
8079
* @param info - Driver and Client properties.
8180
*/
@@ -267,22 +266,6 @@ private Map<String, String> parseUrl(String url) throws SQLException {
267266
return properties;
268267
}
269268

270-
/**
271-
* Creates initial properties with defaults.
272-
* @return mutable HashMap with default values.
273-
*/
274-
Map<String, String> createProperties() {
275-
Map<String, String> props = new HashMap<>();
276-
277-
// Requires to wait result on insert
278-
props.put(DriverProperties.serverSetting(ServerSettings.ASYNC_INSERT), ServerSettings.OFF);
279-
280-
// Requires to wait result of query (manly insert)
281-
props.put(DriverProperties.serverSetting(ServerSettings.WAIT_END_OF_QUERY), ServerSettings.ON);
282-
283-
return props;
284-
}
285-
286269
/**
287270
* Combines url properties and provided ones via {@link java.sql.Driver#connect(String, Properties)}
288271
* @param urlProperties - properties parsed from URL
@@ -291,7 +274,7 @@ Map<String, String> createProperties() {
291274
private void buildFinalProperties(Map<String, String> urlProperties, Properties providedProperties) {
292275

293276
// Copy provided properties
294-
Map<String, String> props = createProperties();
277+
Map<String, String> props = new HashMap<>();
295278
// Set driver properties defaults (client will do the same)
296279
for (DriverProperties prop : DriverProperties.values()) {
297280
if (prop.getDefaultValue() != null) {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.clickhouse.client.ClickHouseProtocol;
55
import com.clickhouse.client.ClickHouseServerForTest;
66
import com.clickhouse.client.api.ClientConfigProperties;
7+
import com.clickhouse.client.api.internal.ServerSettings;
78
import com.clickhouse.client.api.query.GenericRecord;
89
import com.clickhouse.data.ClickHouseVersion;
910
import com.clickhouse.logging.Logger;
@@ -13,11 +14,16 @@
1314
import java.sql.SQLException;
1415
import java.sql.Statement;
1516
import java.util.List;
17+
import java.util.Map;
1618
import java.util.Properties;
1719

1820
public abstract class JdbcIntegrationTest extends BaseIntegrationTest {
1921
private static final Logger LOGGER = LoggerFactory.getLogger(JdbcIntegrationTest.class);
2022

23+
public static final String WAIT_ASYNC_SETTING_KEY = DriverProperties.serverSetting(ServerSettings.WAIT_ASYNC_INSERT);
24+
public static final String WAIT_QUERY_SETTING_KEY = DriverProperties.serverSetting(ServerSettings.WAIT_END_OF_QUERY);
25+
public static final String ASYNC_INSERT_SETTING_KEY = DriverProperties.serverSetting(ServerSettings.ASYNC_INSERT);
26+
2127
public String getEndpointString() {
2228
return getEndpointString(isCloud());
2329
}
@@ -28,7 +34,13 @@ public String getEndpointString(boolean includeDbName) {
2834
}
2935

3036
public Connection getJdbcConnection() throws SQLException {
31-
return getJdbcConnection(null);
37+
return getJdbcConnection((Properties) null);
38+
}
39+
40+
public Connection getJdbcConnection(Map<String, Object> propertiesMap) throws SQLException {
41+
Properties config = new Properties();
42+
config.putAll(propertiesMap);
43+
return getJdbcConnection(config);
3244
}
3345

3446
public Connection getJdbcConnection(Properties properties) throws SQLException {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.clickhouse.jdbc;
22

33
import com.clickhouse.client.api.DataTypeUtils;
4+
import com.clickhouse.client.api.internal.ServerSettings;
45
import com.clickhouse.data.ClickHouseColumn;
56
import com.clickhouse.data.ClickHouseDataType;
67
import com.clickhouse.data.ClickHouseVersion;
@@ -956,7 +957,7 @@ void testBatchInsertTextStatement(String sql) throws Exception {
956957
String table = "test_batch_text";
957958
long seed = System.currentTimeMillis();
958959
Random rnd = new Random(seed);
959-
try (Connection conn = getJdbcConnection()) {
960+
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
960961

961962
try (Statement stmt = conn.createStatement()) {
962963
stmt.execute("CREATE TABLE IF NOT EXISTS " + table +
@@ -1007,7 +1008,7 @@ void testBatchInsertNoValuesReuse() throws Exception {
10071008
String sql = "INSERT INTO %s (v1, v2) VALUES (?, ?)";
10081009
long seed = System.currentTimeMillis();
10091010
Random rnd = new Random(seed);
1010-
try (Connection conn = getJdbcConnection()) {
1011+
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
10111012

10121013
try (Statement stmt = conn.createStatement()) {
10131014
stmt.execute("CREATE TABLE IF NOT EXISTS " + table +
@@ -1062,7 +1063,7 @@ void testBatchInsertValuesReuse() throws Exception {
10621063
String sql = "INSERT INTO %s (v1, v2) VALUES (1, ?)";
10631064
long seed = System.currentTimeMillis();
10641065
Random rnd = new Random(seed);
1065-
try (Connection conn = getJdbcConnection()) {
1066+
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
10661067

10671068
try (Statement stmt = conn.createStatement()) {
10681069
stmt.execute("CREATE TABLE IF NOT EXISTS " + table +
@@ -1266,7 +1267,7 @@ public void testJdbcEscapeSyntax() throws Exception {
12661267

12671268
@Test(groups = {"integration "})
12681269
public void testStatementsWithDatabaseInTableIdentifier() throws Exception {
1269-
try (Connection conn = getJdbcConnection()) {
1270+
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
12701271
final String db1Name = conn.getSchema() + "_db1";
12711272
final String table1Name = "table1";
12721273
try (Statement stmt = conn.createStatement()) {
@@ -1296,7 +1297,7 @@ public void testStatementsWithDatabaseInTableIdentifier() throws Exception {
12961297

12971298
@Test(groups = {"integration "})
12981299
public void testNullValues() throws Exception {
1299-
try (Connection conn = getJdbcConnection()) {
1300+
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
13001301
final String table = "test_null_values";
13011302
try (Statement stmt = conn.createStatement()) {
13021303
stmt.execute("DROP TABLE IF EXISTS " + table);

0 commit comments

Comments
 (0)