[FLINK-40305][core] Decode VARIANT strings and object keys as UTF-8 - #28919
Open
raminqaf wants to merge 1 commit into
Open
[FLINK-40305][core] Decode VARIANT strings and object keys as UTF-8#28919raminqaf wants to merge 1 commit into
raminqaf wants to merge 1 commit into
Conversation
Collaborator
`BinaryVariantUtil` decoded string values and object field names with `new String(byte[], int, int)`, which uses the JVM default charset, while `BinaryVariantInternalBuilder` writes both as UTF-8. The two only agree on Java 18+, where JEP 400 made UTF-8 the default charset. On Java 11 and 17 a non-UTF-8 platform charset corrupts any non-ASCII text. Corrupted field names are the worse half of this. `getField(name)` silently returns null, and `getFieldNames()` and `toJson()` return mangled keys. Both call sites now pass `StandardCharsets.UTF_8` explicitly, matching Spark's `VariantUtil`.
raminqaf
force-pushed
the
FLINK-40305-utf8-variant
branch
from
August 4, 2026 13:25
302d737 to
2349642
Compare
twalthr
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief change log
BinaryVariantUtil.getStringdecodes string values as UTF-8 instead of using the JVM default charsetBinaryVariantUtil.getMetadataKeydecodes object field names the same wayVerifying this change
This change added tests and can be verified as follows:
BinaryVariantTest.testNonAsciiStringsAndFieldNamesbuilds an object with non-ASCII field names and values, then re-reads it throughnew BinaryVariant(value, metadata). That is the path taken once a variant has been serialized, and the only one that decodes field namesfrom the metadata dictionary. It asserts
getFieldNames(),getField(...),getString()andtoJson(). The values cover both string encodings, one short and one pastMAX_SHORT_STR_SIZEsoLONG_STRis exercised too.BinaryVariantInternalBuilderTest.testParseJsonWithNonAsciiStringsAndKeyscovers thePARSE_JSONpath with non-ASCII keys and values, and asserts the document round-trips byte for byte.-Dfile.encoding=ISO-8859-1, and pass with the fix applied. On a UTF-8 JVM they pass either way. That is inherent to the bug rather than a gap in the tests, since JEP 400 makes UTF-8 the default from Java 18 on.Does this pull request potentially affect one of the following parts:
@Public(Evolving): no.BinaryVariantUtilis@Internal. The observable behaviour of@PublicEvolving Variantdoes change, but only so that non-ASCII text decodes correctly. No signatures change.VariantSerializerwrites and reads the rawvalueandmetadatabyte arrays, and the binary layout is untouched, so existing state stays readable. Nothing was corrupted at rest either. The writer always encoded UTF-8, so only the read path was affected.getStringandgetMetadataKeyrun per record for VARIANT access. Naming the charset adds no work. On Java 18+ it selects the same decoder the JDK already picked implicitly.Documentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Claude Opus 5)