-
Notifications
You must be signed in to change notification settings - Fork 622
[client-v2, jdbc-v2] Lazy String instantiation, Read bytes to buffer first#2813
[client-v2, jdbc-v2] Lazy String instantiation, Read bytes to buffer first #2813chernser wants to merge 9 commits into
Conversation
chernser
commented
Apr 9, 2026
This implementation is bad. Closing PR.
...ing with typehinting
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
chernser
commented
Apr 10, 2026
@claude[agent] review changes. give short summary in comment.
@claude[agent] review changes. give short summary in comment.
Review Summary
Changed: This PR adds lazy String instantiation by reading string bytes into ByteBuffers first, with opt-in BinaryString type for deferred conversion. Also includes Session API formalization, improved error messages, Variant null handling, and DNS/auth fixes.
Core Changes:
BinaryStringinterface withBinaryStringImplfor lazy String conversion via ByteBuffer (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java:1452-1504)- Type hint system allowing
BinaryString.classto defer String allocation (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java:135-146) - Session extracted into dedicated
Sessionclass with thread-safe operations (client-v2/src/main/java/com/clickhouse/client/api/Session.java:1-100)
Compatibility Risk: MEDIUM
Breaking/High-Risk Changes:
readValue()signature changed to acceptClass<?>type hint - impacts internal callers in AbstractBinaryFormatReader- Array/Map item reading now forces String.class hint instead of BinaryString - prevents unexpected type changes in collections (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java:684,867)
- Variant null discriminator byte handling changed:
0xFFnow treated as null (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java:916-918) readValue()error context enhanced with row number and timing - exception messages changedBinaryStringImpl.asBytes()throwsUnsupportedOperationExceptionfor off-heap buffers - new failure modeAbstractBinaryFormatReader.readValue()now unwraps BinaryString to String automatically - output type preserved
Issues Found:
-
Bug - Incorrect buffer handling in BinaryStringImpl (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/BinaryStreamReader.java:1487-1492)
new String(buffer.array(), ...)reads entire backing array, not just the buffer range- Should use
new String(buffer.array(), buffer.position(), buffer.remaining(), ...) - Impact: Extra bytes or incorrect strings when buffer doesn't start at 0 or uses a slice
-
Inconsistency - Missing BinaryString unwrapping in readValue(String) (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java:230)
readValue(int)unwraps BinaryString, butreadValue(String)delegates without unwrapping- Impact: Column-by-name access could return BinaryString when column-by-index returns String
-
Performance - Unnecessary allocation in error path (client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java:260-269)
timeSinceLastNext()called twice per exception- Minor: Pre-calculate before constructing message
Tests: Variant null tests added and passing. No dedicated BinaryString tests visible in diff. Session tests added.
Docs: No changes to docs/features.md despite new type-hint API being user-facing in custom reader scenarios.
Quality Gate Failed Quality Gate failed
Failed conditions
77.5% Coverage on New Code (required ≥ 80%)
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions!
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions!
Summary
Closes #2263
Closes #2558
Closes #2608
Checklist
Delete items not relevant to your PR: