-
Notifications
You must be signed in to change notification settings - Fork 618
Adds ability to read strings as byte[]
#2734
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
...rc/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java
Outdated
Show resolved
Hide resolved
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
JDBC V1 CoverageCoverage Report
Class Coverage
|
Client V1 CoverageCoverage Report
Class Coverage
|
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 adds support for reading and writing byte[] as binary strings in the JDBC driver, treating strings as byte arrays for compatibility with binary data operations.
Changes:
- Added
convertToUnhexExpression()utility to encodebyte[]asunhex(<hexstring>)SQL expressions forPreparedStatement#setBytes - Extended
ResultSet#getBytesand reader methods to return UTF-8 bytes of String values or raw address bytes of InetAddress objects - Refactored
AbstractBinaryFormatReaderto route column-name-based getters through index-based implementations for consistency
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java | Updated test to use plain SELECT ? instead of Array(Int8) cast for setBytes |
| jdbc-v2/src/test/java/com/clickhouse/jdbc/JdbcDataTypeTests.java | Added integration tests for IP address byte retrieval and string/fixed-string round-tripping via setBytes/getBytes |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java | Introduced convertToUnhexExpression() to hex-encode byte arrays as SQL unhex expressions |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java | Swapped getBytes implementation to call index-based method from name-based variant |
| jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java | Added byte[] encoding via unhex expression in encodeObject() |
| client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java | Refactored to consolidate name-based getters onto index-based logic and added String/InetAddress→byte[] conversion in getPrimitiveArray() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcUtils.java
Outdated
Show resolved
Hide resolved
...rc/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java
Show resolved
Hide resolved
...rc/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java
Outdated
Show resolved
Hide resolved
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.
Cursor Bugbot has reviewed your changes and found 4 potential issues.
kurnoolsaketh
left a comment
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.
besides my two comments below, the changes here look fine 👍 - most of this diff is code refactoring in AbstractBinaryFormatReader. Please get @mzitnik's feedback before merging.
...rc/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java
Show resolved
Hide resolved
|


Summary
PreparedStatement#setBytesused -byte[]encoded asunhex(<hexstring>)that will let write binary stringsResultSet#getBytesused - thenbyte[]of String object will be returned. Note: still not optimal and internally logic will be changed to store strings asbyte[]and create them on demand.Checklist
Delete items not relevant to your PR:
Note
Medium Risk
Changes JDBC parameter encoding and binary-format value coercion for
byte[], which can affect howString/FixedStringand IP types are serialized/deserialized; covered by new integration/unit tests but touches core ResultSet/PreparedStatement paths.Overview
Adds end-to-end support for treating
byte[]as binary strings in JDBC.PreparedStatement#setBytesnow serializesbyte[]as a ClickHouseunhex('<hex>')expression (via newJdbcUtils.convertToUnhexExpression/decodeHexStringhelpers) to preserve raw bytes.On the read path,
ResultSet#getBytes(int)is switched to use the binary reader’sgetByteArray(index)directly, and the underlyingAbstractBinaryFormatReaderis updated to allowgetByteArray()to coerceString/FixedStringvalues (UTF-8) andInetAddressvalues (raw address bytes) intobyte[]. Tests are added/updated to validate bytes round-tripping for strings, fixed strings, and IP address columns, and the performance module’s Testcontainers ClickHouse dependency is updated totestcontainers-clickhousev2.0.2.Written by Cursor Bugbot for commit 04513dd. This will update automatically on new commits. Configure here.