Skip to content

Conversation

@chernser
Copy link
Contributor

@chernser chernser commented Jun 25, 2025

Summary

  • made client settings handling more streamlined

Closes #2359

Checklist

Delete items not relevant to your PR:

  • Closes #
  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

@chernser chernser marked this pull request as ready for review June 27, 2025 05:48
@chernser chernser requested review from Copilot and mzitnik June 27, 2025 05:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR streamlines client settings handling by migrating to a typed Map<String, Object> approach, enhances JSON handling in JDBC tests, and adds table-name parsing in the SQL parser.

  • Added table name extraction in ParsedPreparedStatement and logged it in the SQL parser tests.
  • Refactored client-side configuration to use ClientConfigProperties and typed maps.
  • Cleaned up debug output in tests and updated expected values to match new settings behavior.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/SqlParserTest.java Added debug println for table extraction in parser tests.
jdbc-v2/src/test/java/com/clickhouse/jdbc/DataTypeTests.java Switched from getConnection() to getJdbcConnection(), enabled JSON test, and adjusted annotations.
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/ParsedPreparedStatement.java Added enterTableExprIdentifier to capture table identifiers.
client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java Removed leftover debug println.
client-v2/src/test/java/com/clickhouse/client/HttpTransportTests.java Updated expected async_insert value in mock server test.
client-v2/src/test/java/com/clickhouse/client/ClientTests.java Adjusted expected configuration size counts.
client-v2/src/main/java/com/clickhouse/client/api/query/QuerySettings.java Made rawSettings final, added constructor, updated httpHeader usage.
client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java Refactored to use typed config map, removed MapUtils, and updated HTTP client setup.
client-v2/src/main/java/com/clickhouse/client/api/query/QuerySettings.java Ensured consistent builder chaining and default initialization.
client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java Expanded property definitions, added parsing logic for typed values.
client-v2/src/main/java/com/clickhouse/client/api/Client.java Migrated to Map<String, Object> config, merged client and operation settings.
clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseServerForTest.java Removed unreachable debug exception block.
Comments suppressed due to low confidence (2)

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

  • [nitpick] Remove or replace this debug println. Consider asserting on the extracted table name instead of printing to stdout.
        System.out.println(stmt.getTable());

client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java:500

  • This method no longer handles server settings (keys starting with ClientConfigProperties.SERVER_SETTING_PREFIX), so server-side settings in requestConfig won't be added as query parameters. Reintroduce iteration over requestConfig for keys with the server setting prefix and add them via req.addParameter(...).
    private void addQueryParams(URIBuilder req, Map<String, Object> requestConfig) {

Copy link
Contributor

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other comments (3)

💡 To request another review, post a new comment with "/windsurf-review".

Comment on lines +1090 to +1094
try (Connection conn = getJdbcConnection(props)) {
try (Statement stmt = conn.createStatement()) {
try (ResultSet rs = stmt.executeQuery("SELECT * FROM test_json ORDER BY order")) {
assertTrue(rs.next());
assertEquals(rs.getString("json"), json);

assertEquals(rs.getString("json"), serverJson);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON test now correctly configures server settings for JSON handling, but it would be more comprehensive to also test retrieving the JSON as an object (using getObject("json")) and verify its structure, not just the string representation.

@github-actions
Copy link

Client V2 Coverage

Coverage Report

Package Coverage Lines Covered Total Lines
com.clickhouse.client.api 84.51% 682 807
com.clickhouse.client.api.command 50.00% 8 16
com.clickhouse.client.api.data_formats 39.30% 134 341
com.clickhouse.client.api.data_formats.internal 59.69% 1066 1786
com.clickhouse.client.api.enums 100.00% 5 5
com.clickhouse.client.api.http 0.00% 1
com.clickhouse.client.api.insert 70.83% 51 72
com.clickhouse.client.api.internal 75.00% 540 720
com.clickhouse.client.api.metadata 85.42% 41 48
com.clickhouse.client.api.metrics 93.75% 75 80
com.clickhouse.client.api.query 59.42% 82 138
com.clickhouse.client.api.serde 84.21% 48 57
com.clickhouse.client.api.transport 83.33% 10 12
Class Coverage
Class Coverage Lines Covered Total Lines
com.clickhouse.client.api.ClickHouseException 62.50% 5 8
com.clickhouse.client.api.Client 82.93% 345 416
com.clickhouse.client.api.Client.Builder 80.00% 156 195
com.clickhouse.client.api.Client.new DataStreamWriter() {...} 100.00% 8 8
com.clickhouse.client.api.ClientConfigProperties 97.62% 123 126
com.clickhouse.client.api.ClientConfigProperties.new ClientConfigProperties() {...} 100.00% 8 8
com.clickhouse.client.api.ClientException 100.00% 4 4
com.clickhouse.client.api.ClientFaultCause 100.00% 7 7
com.clickhouse.client.api.ClientMisconfigurationException 100.00% 4 4
com.clickhouse.client.api.command.CommandResponse 46.67% 7 15
com.clickhouse.client.api.command.CommandSettings 100.00% 1 1
com.clickhouse.client.api.ConnectionInitiationException 50.00% 3 6
com.clickhouse.client.api.ConnectionReuseStrategy 100.00% 3 3
com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader 71.99% 203 282
com.clickhouse.client.api.data_formats.internal.AbstractBinaryFormatReader.RecordWrapper 50.00% 17 34
com.clickhouse.client.api.data_formats.internal.BinaryReaderBackedRecord 13.75% 11 80
com.clickhouse.client.api.data_formats.internal.BinaryStreamReader 65.00% 234 360
com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.ArrayValue 74.19% 23 31
com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.CachingByteBufferAllocator 100.00% 8 8
com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.DefaultByteBufferAllocator 100.00% 2 2
com.clickhouse.client.api.data_formats.internal.BinaryStreamReader.EnumValue 77.78% 7 9
com.clickhouse.client.api.data_formats.internal.InetAddressConverter 66.67% 18 27
com.clickhouse.client.api.data_formats.internal.MapBackedRecord 24.62% 32 130
com.clickhouse.client.api.data_formats.internal.NumberConverter 86.81% 79 91
com.clickhouse.client.api.data_formats.internal.NumberConverter.NumberType 100.00% 7 7
com.clickhouse.client.api.data_formats.internal.ProcessParser 80.00% 32 40
com.clickhouse.client.api.data_formats.internal.SerializerUtils 57.18% 390 682
com.clickhouse.client.api.data_formats.internal.SerializerUtils.DynamicClassLoader 100.00% 3 3
com.clickhouse.client.api.data_formats.NativeFormatReader 84.00% 42 50
com.clickhouse.client.api.data_formats.NativeFormatReader.Block 66.67% 12 18
com.clickhouse.client.api.data_formats.RowBinaryFormatReader 17.65% 3 17
com.clickhouse.client.api.data_formats.RowBinaryFormatSerializer 17.27% 19 110
com.clickhouse.client.api.data_formats.RowBinaryFormatWriter 27.84% 27 97
com.clickhouse.client.api.data_formats.RowBinaryFormatWriter.InputStreamHolder 0.00% 4
com.clickhouse.client.api.data_formats.RowBinaryFormatWriter.ReaderHolder 0.00% 4
com.clickhouse.client.api.data_formats.RowBinaryWithNamesAndTypesFormatReader 90.00% 18 20
com.clickhouse.client.api.data_formats.RowBinaryWithNamesFormatReader 61.90% 13 21
com.clickhouse.client.api.DataStreamWriter 0.00% 1
com.clickhouse.client.api.DataTransferException 50.00% 2 4
com.clickhouse.client.api.DataTypeUtils 75.00% 3 4
com.clickhouse.client.api.enums.Protocol 100.00% 2 2
com.clickhouse.client.api.enums.ProxyType 100.00% 3 3
com.clickhouse.client.api.http.ClickHouseHttpProto 0.00% 1
com.clickhouse.client.api.insert.InsertResponse 58.33% 7 12
com.clickhouse.client.api.insert.InsertSettings 73.33% 44 60
com.clickhouse.client.api.internal.BasicObjectsPool 0.00% 11
com.clickhouse.client.api.internal.CachingObjectsSupplier 0.00% 10
com.clickhouse.client.api.internal.ClickHouseLZ4InputStream 87.67% 64 73
com.clickhouse.client.api.internal.ClickHouseLZ4OutputStream 92.31% 60 65
com.clickhouse.client.api.internal.ClientStatisticsHolder 50.00% 7 14
com.clickhouse.client.api.internal.EnvUtils 0.00% 14
com.clickhouse.client.api.internal.Gauge 66.67% 4 6
com.clickhouse.client.api.internal.HttpAPIClientHelper 88.03% 309 351
com.clickhouse.client.api.internal.HttpAPIClientHelper.DummySSLConnectionSocketFactory 0.00% 3
com.clickhouse.client.api.internal.HttpAPIClientHelper.MeteredManagedHttpClientConnectionFactory 50.00% 7 14
com.clickhouse.client.api.internal.LZ4Entity 86.84% 33 38
com.clickhouse.client.api.internal.MapUtils 37.10% 23 62
com.clickhouse.client.api.internal.ServerSettings 0.00% 1
com.clickhouse.client.api.internal.StopWatch 64.29% 9 14
com.clickhouse.client.api.internal.TableSchemaParser 85.71% 18 21
com.clickhouse.client.api.internal.ValidationUtils 30.00% 6 20
com.clickhouse.client.api.internal.ValidationUtils.SettingsValidationException 0.00% 3
com.clickhouse.client.api.metadata.DefaultColumnToMethodMatchingStrategy 100.00% 13 13
com.clickhouse.client.api.metadata.NoSuchColumnException 0.00% 2
com.clickhouse.client.api.metadata.TableSchema 84.85% 28 33
com.clickhouse.client.api.metrics.ClientMetrics 100.00% 7 7
com.clickhouse.client.api.metrics.MicrometerLoader 90.91% 40 44
com.clickhouse.client.api.metrics.OperationMetrics 94.12% 16 17
com.clickhouse.client.api.metrics.ServerMetrics 100.00% 12 12
com.clickhouse.client.api.query.NullValueException 50.00% 2 4
com.clickhouse.client.api.query.QueryResponse 66.67% 24 36
com.clickhouse.client.api.query.QuerySettings 55.88% 38 68
com.clickhouse.client.api.query.QueryStatement 0.00% 4
com.clickhouse.client.api.query.Records 61.90% 13 21
com.clickhouse.client.api.query.Records.new Iterator() {...} 100.00% 5 5
com.clickhouse.client.api.serde.DataSerializationException 0.00% 6
com.clickhouse.client.api.serde.POJOSerDe 97.96% 48 49
com.clickhouse.client.api.serde.SerializerNotFoundException 0.00% 2
com.clickhouse.client.api.ServerException 84.62% 11 13
com.clickhouse.client.api.transport.HttpEndpoint 83.33% 10 12

boolean hasPassword = this.configuration.containsKey(ClientConfigProperties.PASSWORD.getKey());
boolean customHttpHeaders = this.configuration.containsKey(ClientConfigProperties.httpHeader(HttpHeaders.AUTHORIZATION));

if (!(useSslAuth || hasAccessToken || hasUser || hasPassword || customHttpHeaders)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to mention what exactly is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is when nothing is specified. That we say in the exception message

boolean customHttpHeaders = this.configuration.containsKey(ClientConfigProperties.httpHeader(HttpHeaders.AUTHORIZATION));

if (!(useSslAuth || hasAccessToken || hasUser || hasPassword || customHttpHeaders)) {
throw new IllegalArgumentException("Username and password (or access token or SSL authentication or pre-define Authorization header) are required");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to wrap it as a client exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine - it is not even a client yet.

@mzitnik
Copy link
Contributor

mzitnik commented Jun 29, 2025

The PR message is misleading

@chernser chernser changed the title [jdbc-v2, client-v2] Fixes few issues JSON in JDBC [jdbc-v2, client-v2] Fix configuration handling by normalizing it. Jun 30, 2025
@chernser chernser merged commit 3503209 into main Jun 30, 2025
17 of 23 checks passed
@chernser chernser deleted the jdbc_fix_json_issues branch June 30, 2025 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Failed to read row" with JDBC v2 & OUTPUT_FORMAT_BINARY_WRITE_JSON_AS_STRING

3 participants