-
Notifications
You must be signed in to change notification settings - Fork 614
[jdbc-v2] bug fix for UInt32 UInt64 and Added support for Nested Type #2334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 pull request addresses a bug fix for the handling of UInt32/UInt64 types and adds support for non‐flattened Nested types.
- Updated SQL type mapping for UInt32 and removed the mapping for UInt64 in JdbcUtils to fix type handling issues.
- Expanded unit tests in DataTypeTests to cover getObject for various numeric types, including the new nested types.
- Added support for Nested types in BinaryStreamReader by introducing the readNested method and a corresponding case in readValue.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| jdbc-v2/src/test/java/com/clickhouse/jdbc/DataTypeTests.java | Added getObject tests for integers, decimals, dates, arrays, booleans, and nested types. |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java | Adjusted type mapping for UInt32 and removed UInt64 mapping for improved type representation. |
| client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java | Introduced new support for non-flattened Nested types by adding a Nested case in readValue and the readNested method. |
Comments suppressed due to low confidence (2)
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java:47
- Changing the mapping for UInt32 to BIGINT appears correct; however, the removal of the UInt64 mapping may cause unexpected behavior if explicit type handling for UInt64 is required. Verify that the fallback or alternative mechanism for processing UInt64 values is intentional and fully tested.
map.put(ClickHouseDataType.UInt32, JDBCType.BIGINT);
client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java:237
- Ensure that using convertArray with readNested correctly handles Nested type conversion. Adding additional unit tests for various nested data structures may help verify that this new logic covers all expected scenarios.
case Nested:
|
Fixing test errors |
|
create table with setting To avoid this, I used query It is worth mentioning that I change the behavior of |
There was a problem hiding this 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 fixes a bug in ResultSet.getObject() for UInt32/UInt64 types and adds support for nested types in BinaryStreamReader, along with enhancements to session settings and profile handling.
- Fixes data type mapping for UInt32 and removes redundant mapping for UInt64.
- Adds new tests to validate getObject() behavior for various numeric, date, and nested types.
- Introduces support for setting session-level profile and server settings via SQL and HTTP API.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| jdbc-v2/src/test/java/com/clickhouse/jdbc/metadata/DatabaseMetaDataTest.java | Updated column definitions and ordering to account for the new UInt128/huge_integer type. |
| jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java | Added tests for SET session settings and profile support. |
| jdbc-v2/src/test/java/com/clickhouse/jdbc/DataTypeTests.java | Extended tests for getObject() with various data types, including high-precision numerics. |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java | Modified mapping for UInt32 from INTEGER to BIGINT. |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java | Updated SQL parsing logic to handle profile and session settings. |
| client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java | Added support for sending profile parameter in HTTP requests. |
| client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java | Extended handling for Nested data types with new readNested implementation. |
| client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java | Introduced a new PROFILE property. |
| client-v2/src/main/java/com/clickhouse/client/api/Client.java | Added setProfile() to update client configuration. |
Comments suppressed due to low confidence (3)
jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java:380
- [nitpick] Consider refactoring the SQL token parsing for SET statements to avoid relying solely on fixed token positions; a more robust approach could prevent potential misinterpretations when SQL syntax varies.
} else if (JdbcUtils.containsIgnoresCase(tokens, "="){
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java:47
- Ensure that mapping UInt32 to JDBCType.BIGINT is fully consistent with the expected data range and any relevant documentation, as this change may affect how large values are retrieved.
map.put(ClickHouseDataType.UInt32, JDBCType.BIGINT);
client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java:237
- Verify that the new 'Nested' case in the readValue method correctly handles type conversion via convertArray(readNested(actualColumn), typeHint) and consider adding explicit checks or logging for type mismatches.
case Nested:
correction: previous
already fixed and added test to cover |
| } | ||
| } | ||
|
|
||
| } else if (JdbcUtils.containsIgnoresCase(tokens, "=")){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be true for any string containing "="
it may be would work for simple case.
just to note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, there may be a multiline string so next lines should be analyzed, too.
| String key = tokens.get(1); | ||
| String value = tokens.get(3).replace("'", ""); | ||
| //SET profile | ||
| if (key.equals("profile")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equalsIgnoreCase ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Settings and profile seem to be case sensitive, and ClickHouse will return error UNKNOWN_SETTING if the key is not recognized
|
Good day, @gfunc ! Would you please explain your fix for the UInt32/UInt64? Thanks you! |
|
Good day! @chernser Since the recent releases changed how the v2 driver chooses JDBC type and Java class for ClickHouse data types, it seems it will force the same Java class for the same JDBC type. My fix for UInt32/Uint64 is simple:
As for changes related to the |
| map.put(ClickHouseDataType.UInt32, JDBCType.INTEGER); | ||
| map.put(ClickHouseDataType.UInt32, JDBCType.BIGINT); | ||
| map.put(ClickHouseDataType.Int64, JDBCType.BIGINT); | ||
| map.put(ClickHouseDataType.UInt64, JDBCType.BIGINT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that UInt64 is not mapped to anything, right? I think it is not correct.
UInt64 is not Other just because it is represent by BigInteger. This mapping is mainly for metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right in some way.
But UInt32 and UInt64 are both OTHER because JDBC type is valid only for signed numbers.
Would you please remove UInt8, UInt16, UInt32 and UInt64 from this mapping? We should return whatever BinaryStreamReader returns.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all Uint had been removed
|
@gfunc |
|
@gfunc |
|
Hi @chernser |
Summary
added support for set session settings and set profileCloses
Checklist
Delete items not relevant to your PR: