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.
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
|
kurnoolsaketh
left a comment
There was a problem hiding this comment.
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.
| return (T)array; | ||
| } else if (componentType == byte.class) { | ||
| if (value instanceof String) { | ||
| return (T) ((String) value).getBytes(StandardCharsets.UTF_8); |
There was a problem hiding this comment.
According to our docs:
ClickHouse does not have the concept of encodings. Strings can contain an arbitrary set of bytes, which are stored and output as-is.
do we document anywhere that the java client reads Strings in byte arrays as UTF_8?
There was a problem hiding this comment.
good point. Will add to documentation.
There was a problem hiding this comment.
Added to local PR - will update shortly
| * @param bytes byte array | ||
| * @return non-null expression | ||
| */ | ||
| public static String convertToUnhexExpression(byte[] bytes) { |
There was a problem hiding this comment.
the logic is sensible, but can you add a unit test for this function? This will make the logic much more understandable.


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
Touches JDBC parameter encoding and binary result decoding paths, which could change how
String/IP values are surfaced as bytes and affect existing users relying on prior behaviors.Overview
Enables JDBC
PreparedStatement#setBytesto writebyte[]as ClickHouse binary strings by encoding parameters asunhex('<hex>')expressions.Improves
ResultSet#getBytesand the underlying binary reader sogetByteArray()can return bytes not only from Array values, but also fromString(UTF-8) andInetAddressvalues, and refactors manygetXxx(String)methods to delegate to index-based implementations.Adds integration tests covering
getBytes()for IP types and round-trippingbyte[]intoString/FixedString, updates thesetBytesintegration test accordingly, and bumps the performance module’s Testcontainers ClickHouse dependency (clickhouse->testcontainers-clickhouse, version2.0.2).Written by Cursor Bugbot for commit ebc913b. This will update automatically on new commits. Configure here.