Repository navigation
[jdbc-v2] Cut FixedString text after the last valid UTF-8 character in getString and getObject - #3427
polyglotAI-bot wants to merge 2 commits into
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)
|
| * from the end. The same characters inside the value are kept. The text of other column types is returned | ||
| * unchanged. | ||
| */ | ||
| private String trimFixedString(String columnLabel, String value) { |
There was a problem hiding this comment.
but this also will cut 2, 3 ,4 byte characters incorrectly so they will look agly. We can detect it and cut before.
There was a problem hiding this comment.
I checked this. The cut character is already removed. client-v2 decodes the FixedString bytes as UTF-8, and the first 1, 2 or 3 bytes of a 2-, 3- or 4-byte character decode to one U+FFFD (the same on JDK 8 and JDK 17). The loop removes the trailing U+FFFD together with the \0 padding, so the text ends with the last complete character:
| Value | Bytes | getString |
|---|---|---|
toFixedString(left('aé', 2), 4) |
61 C3 00 00 |
"a" |
toFixedString(left('a€', 2), 2) |
61 E2 |
"a" |
toFixedString(left('a€', 3), 6) |
61 E2 82 00 00 00 |
"a" |
toFixedString(left('a😀', 2), 2) |
61 F0 |
"a" |
toFixedString(left('a😀', 3), 5) |
61 F0 9F 00 00 |
"a" |
toFixedString(left('a😀', 4), 4) |
61 F0 9F 98 |
"a" |
toFixedString(left('é€😀', 8), 10) |
C3 A9 E2 82 AC F0 9F 98 00 00 |
"é€" |
In 61931bf I added these rows to testFixedStringTextRead (with binary_string_support off and on), and the Javadoc now says this. With a trim of \0 only, these 16 cases fail and the text ends in U+FFFD.
One limit: jdbc-v2 gets the decoded text, not the bytes (client-v2 decodes FixedString when binary_string_support is off). So a real U+FFFD (EF BF BD) at the end is also removed. To keep it, the check must run on the bytes before the decoding, and that needs a change in client-v2. Do you want that, or is the current result correct for you?
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.