Repository navigation
[jdbc-v2] Cut FixedString text after the last valid UTF-8 character in getString and getObject - #3427
Conversation
ResultSet#getString and ResultSet#getObject (when the result is a String) cut a FixedString(N) value after its last valid UTF-8 character: the zero bytes that the server adds to a value shorter than N bytes, and an incomplete multi-byte character at the end, are removed. Only top-level FixedString columns change. The binary accessors still return all N bytes. Implements: #3288 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Docs drift check: resolved, docs now match this PR's changes. |
There was a problem hiding this comment.
Auto-approved by the AI review gate on 2887bb5. Details in the approver's comment on this pull request.
AI review gate — auto-approved
History (latest 5 heads, newest first)
|
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
Add test rows for a FixedString value that ends in the first 1, 2 or 3 bytes of a 2-, 3- or 4-byte character, with and without zero padding. Each cut character decodes to one U+FFFD, which getString and getObject remove. Explain this in the trimFixedString Javadoc. Update docs/clickhouse-docs/jdbc.mdx: jdbc-v2 no longer reads FixedString text with the zero padding, and V1 and V2 are different here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Docs drift check: 61931bf updates both sections of |
There was a problem hiding this comment.
Auto-approved by the AI review gate on 61931bf. Details in the approver's comment on this pull request.
Summary
Closes #3288
jdbc-v2
getString(...), andgetObject(...)when it returns aString, now cut aFixedString(N)value after its last valid UTF-8 character, as requested in this comment.toFixedString('Dario', 10)is read as"Dario", not"Dario\0\0\0\0\0". The cause is in client-v2:BinaryStreamReaderdecodes allNbytes, so the zero padding becomes trailing\0characters. client-v2 is not changed.ResultSetImpl.trimFixedStringremoves trailing\0(zero bytes) and trailingU+FFFD(bytes that are not valid UTF-8, for example a character cut byleft:toFixedString(left('José', 4), 4)→"Jos"). A realU+FFFDat the end is also removed. The same characters inside the value stay.column.getValueDataType():FixedString,Nullable,LowCardinalityandSimpleAggregateFunction(f, FixedString)columns. The column lookup runs only when the text ends with one of the two characters.getBytes(...)still gives the padded bytes. Tell me if you want a property to turn it off.getNString,getNCharacterStream,getUnicodeStream,FixedStringvalues insideArray/Tuple/Map/Variant/Dynamic, andgetObject(..., Integer.class)and other non-string targets.Compatibility
Behavior change, in
history/latest/3288.mdunder "Breaking changes": an application that removes the zero bytes itself or expectsNcharacters must change.Stringcolumns, the binary accessors (getBytes,getBinaryStream,getObject(..., byte[].class)),NULLvalues and JSONEachRow result sets (noFixedStringcolumn type there) do not change.Test
JdbcDataTypeTests#testFixedStringTextRead(19 values ×binary_string_supportoff/on):getStringby index and label,getObjectwith no type,String.class,Object.classand a type map. Values: padding, full width, empty, trailing spaces, multi-byte characters, a 2-, 3- or 4-byte character cut byleftafter each of its bytes (with and without padding),\0and an invalid byte inside the value, and the four column wrappers.JdbcDataTypeTests#testFixedStringTextReadKeepsOtherValues: the binary accessors keep the padding;StringandArray(FixedString)values keep their\0;NULLstaysnullwithwasNull().main, except the full-width values and the second test.Checklist
history/latest/3288.md)docs/changes_checklist.md: string output changed (onlyFixedStringtext fromgetString/getObject; spaces and inner characters kept); null handling not changed (NULL→null, empty value →"");docs/features.md(jdbc-v2 feature and compatibility entries) anddocs/clickhouse-docs/jdbc.mdx(type mapping and migration guide)🤖 Generated with Claude Code
Note
Medium Risk
This is an externally visible, compatibility-sensitive change to how FixedString values are returned as strings; apps that relied on full N-byte text or manual null trimming may need to switch to binary accessors or update expectations.
Overview
jdbc-v2 now strips trailing zero padding and incomplete UTF-8 from
FixedString(N)when callers usegetString(...)orgetObject(...)paths that yield aString.ResultSetImpladdstrimFixedString, which removes trailing\0andU+FFFDonly for columns whose value type isFixedString(including wrapped variants);getBytes,getBinaryStream, andgetObject(..., byte[].class)still return allNbytes unchanged.Documentation and a breaking-change note (
history/latest/3288.md) describe the V1 vs V2 difference and that tools like Tableau were seeing visible null padding. Integration tests inJdbcDataTypeTestscover padding, UTF-8 edge cases, wrappers, and confirm non-FixedStringand binary accessors are unaffected.Reviewed by Cursor Bugbot for commit 61931bf. Bugbot is set up for automated code reviews on this repo. Configure here.