Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 0.9.9

### Breaking Changes

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

## 0.9.8

### Improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public final class ServerSettings {
public static final String ASYNC_INSERT = "async_insert";

public static final String WAIT_ASYNC_INSERT = "wait_for_async_insert";

// Misc
public static final String ON = "1";

public static final String OFF = "0";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.ClientConfigProperties;
import com.clickhouse.client.api.internal.ServerSettings;

Check warning on line 5 in jdbc-v2/src/main/java/com/clickhouse/jdbc/ConnectionImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import 'com.clickhouse.client.api.internal.ServerSettings'.

See more on https://sonarcloud.io/project/issues?id=ClickHouse_clickhouse-java&issues=AZ2YJO54bDB2X7leCWd3&open=AZ2YJO54bDB2X7leCWd3&pullRequest=2829
import com.clickhouse.client.api.metadata.TableSchema;
import com.clickhouse.client.api.query.GenericRecord;
import com.clickhouse.client.api.query.QuerySettings;
Expand Down Expand Up @@ -110,9 +110,7 @@
this.client.loadServerInfo();
}
this.schema = client.getDefaultDatabase();
this.defaultQuerySettings = new QuerySettings()
.serverSetting(ServerSettings.ASYNC_INSERT, "0")
.serverSetting(ServerSettings.WAIT_END_OF_QUERY, "0");
this.defaultQuerySettings = new QuerySettings();

this.metadata = new DatabaseMetaDataImpl(this, false, url);
this.defaultCalendar = Calendar.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

/**
* Parses URL to get property and target host.
* Properties that are passed in the {@code info} parameter will override that are set in the {@code url}.
* Properties that are passed in the {@code url} will override the {@code info} ones.
* @param url - JDBC url
* @param info - Driver and Client properties.
*/
Expand All @@ -89,7 +89,7 @@

Map<String, String> urlProperties = parseUrl(url);
String tmpConnectionUrl = urlProperties.remove(PARSE_URL_CONN_URL_PROP);
initProperties(urlProperties, props);
buildFinalProperties(urlProperties, props);
Comment thread
chernser marked this conversation as resolved.

// after initializing all properties - set final connection URL
boolean useSSLInfo = Boolean.parseBoolean(props.getProperty(DriverProperties.SECURE_CONNECTION.getKey(), "false"));
Expand Down Expand Up @@ -266,7 +266,12 @@
return properties;
}

private void initProperties(Map<String, String> urlProperties, Properties providedProperties) {
/**
* Combines url properties and provided ones via {@link java.sql.Driver#connect(String, Properties)}
* @param urlProperties - properties parsed from URL
* @param providedProperties - properties object provided by application
*/
private void buildFinalProperties(Map<String, String> urlProperties, Properties providedProperties) {

Check failure on line 274 in jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 25 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=ClickHouse_clickhouse-java&issues=AZ2YJO4mbDB2X7leCWd2&open=AZ2YJO4mbDB2X7leCWd2&pullRequest=2829

// Copy provided properties
Map<String, String> props = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.clickhouse.client.ClickHouseProtocol;
import com.clickhouse.client.ClickHouseServerForTest;
import com.clickhouse.client.api.ClientConfigProperties;
import com.clickhouse.client.api.internal.ServerSettings;
import com.clickhouse.client.api.query.GenericRecord;
import com.clickhouse.data.ClickHouseVersion;
import com.clickhouse.logging.Logger;
Expand All @@ -13,11 +14,16 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import java.util.Properties;

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

public static final String WAIT_ASYNC_SETTING_KEY = DriverProperties.serverSetting(ServerSettings.WAIT_ASYNC_INSERT);
public static final String WAIT_QUERY_SETTING_KEY = DriverProperties.serverSetting(ServerSettings.WAIT_END_OF_QUERY);
public static final String ASYNC_INSERT_SETTING_KEY = DriverProperties.serverSetting(ServerSettings.ASYNC_INSERT);

public String getEndpointString() {
return getEndpointString(isCloud());
}
Expand All @@ -28,7 +34,13 @@ public String getEndpointString(boolean includeDbName) {
}

public Connection getJdbcConnection() throws SQLException {
return getJdbcConnection(null);
return getJdbcConnection((Properties) null);
}

public Connection getJdbcConnection(Map<String, Object> propertiesMap) throws SQLException {
Properties config = new Properties();
config.putAll(propertiesMap);
return getJdbcConnection(config);
}

public Connection getJdbcConnection(Properties properties) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clickhouse.jdbc;

import com.clickhouse.client.api.DataTypeUtils;
import com.clickhouse.client.api.internal.ServerSettings;
import com.clickhouse.data.ClickHouseColumn;
import com.clickhouse.data.ClickHouseDataType;
import com.clickhouse.data.ClickHouseVersion;
Expand Down Expand Up @@ -956,7 +957,7 @@ void testBatchInsertTextStatement(String sql) throws Exception {
String table = "test_batch_text";
long seed = System.currentTimeMillis();
Random rnd = new Random(seed);
try (Connection conn = getJdbcConnection()) {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {

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

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

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

@Test(groups = {"integration "})
public void testStatementsWithDatabaseInTableIdentifier() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
final String db1Name = conn.getSchema() + "_db1";
final String table1Name = "table1";
try (Statement stmt = conn.createStatement()) {
Expand Down Expand Up @@ -1296,7 +1297,7 @@ public void testStatementsWithDatabaseInTableIdentifier() throws Exception {

@Test(groups = {"integration "})
public void testNullValues() throws Exception {
try (Connection conn = getJdbcConnection()) {
try (Connection conn = getJdbcConnection(Map.of(ASYNC_INSERT_SETTING_KEY, ServerSettings.OFF))) {
final String table = "test_null_values";
try (Statement stmt = conn.createStatement()) {
stmt.execute("DROP TABLE IF EXISTS " + table);
Expand Down
Loading
Loading