Repository navigation
Conversation
Collaborator
Contributor
Author
|
@flinkbot run azure |
Variant.getField decoded each key it compared into a new String. Finding a field in a 13-key object could create 13 throwaway strings.
For objects below BINARY_SEARCH_THRESHOLD fields, getField now encodes the wanted key once and compares it with the UTF-8 bytes of the metadata dictionary. Larger objects still decode each key and compare Strings, because the binary search depends on the order in which the builder sorts the keys.
The wanted key is encoded the same way the builder encodes the keys it writes. So below the threshold, getField("a\uD800") now finds the field stored as "a?". Larger objects still miss such a key.
Metadata keys that are not valid UTF-8 no longer match the U+FFFD name that getFieldNames lists for them, in objects below the threshold. Flink does not write such keys, and distinct malformed keys already decoded to the same name.
JMH on JDK 17, 4 lookups per row of 13 keys: 285 ns to 132 ns per row, 1368 to 296 bytes allocated.
Generated-by: Claude Code 2.1.309 (Claude Opus 5.5)
raminqaf
force-pushed
the
variant-field-byte-equality
branch
from
October 24, 2026 06:26
4b611aa to
ec2ef48
Compare
raminqaf
commented
Oct 26, 2026
Comment on lines
+368
to
+369
| // Compare decoded Strings here. The builder sorts fields by | ||
| // String.compareTo, which is not UTF-8 byte order. |
Contributor
Author
There was a problem hiding this comment.
This will be fixed in: https://issues.apache.org/jira/browse/FLINK-41180
1 task done
twalthr
approved these changes
Oct 26, 2026
Contributor
Author
|
Merged as: 82834bb |
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.
What is the purpose of the change
Variant.getFielddecoded every metadata key it compared into a newString.v['a']in SQL calls it once per record, so one lookup in a 13-key object could create 13 throwaway strings.For objects below 32 fields,
getFieldnow encodes the wanted key once and compares UTF-8 bytes with the metadata dictionary. The binary search for larger objects is unchanged. It searches in the builder'sString.compareToorder, which is not the UTF-8 byte order the Parquet Variant spec asks for. Fixing that order is a separate change.JMH on JDK 17, 4 lookups per row of 13 keys:
Two edge cases change below the threshold. Both are pinned by the new tests:
getField("a\uD800")on a field written with that keynullgetField("�")on a key whose bytes are not valid UTF-8nullFlink never writes keys that are not valid UTF-8. Two distinct malformed keys already decoded to the same name.
Brief change log
BinaryVariant.getFieldByKeycompares UTF-8 bytes in its linear search.BinaryVariantUtiladdsencodeKey, whichaddKeyin the builder now uses too, andmetadataKeyEquals.getMetadataKeyshares the key range lookup with it.Verifying this change
This change added tests and can be verified as follows:
BinaryVariantTest#testGetFieldWithUnpairedSurrogate,#testGetFieldWithEmptyKeyand#testGetFieldWithMalformedUtf8Key.Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code 2.1.309 (Claude Opus 5.5)