Uh oh!
There was an error while loading. Please reload this page.
AVRO-4267: [java] Compare bytes as unsigned - #3972
Open
1fanwang wants to merge 1 commit into
Open
Conversation
GenericData used Java signed-byte ordering for byte buffers while BinaryData followed the Avro unsigned-byte order. The same values could therefore sort differently in memory and after encoding. Signed-off-by: 1fanwang <1fannnw@gmail.com>
prashantpiyush1111
approved these changes
Aug 27, 2026
prashantpiyush1111
left a comment
There was a problem hiding this comment.
LGTM. Verified compareByteBuffers() — uses absolute get(index) reads so buffer positions are preserved (heap/sliced/direct/read-only, matches the tests), and the unsigned-compare logic correctly mirrors BinaryData.compareBytes(). Logical types (e.g. decimal) still fall through to the old Comparable path via the instanceof ByteBuffer guard. Good test coverage. No concerns, thanks!
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 freeto 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
Java users who sort generic Avro records containing bytes can get a different order before and after serialization. Before this change,
0x7fsorted after0xffin memory but before it in encoded data. After this change, both paths use Avro's unsigned byte order.GenericData.comparenow compares byte buffers over their remaining ranges with unsigned values and absolute reads. This preserves buffer positions and works with heap, sliced, read-only, and direct buffers. Converted logical types keep the existingComparablebehavior.Fixes https://issues.apache.org/jira/browse/AVRO-4267
Verifying this change
This change adds coverage for unsigned values, prefixes, nonzero positions, sliced buffers, read-only buffers, direct buffers, position preservation, and converted logical types.
Raw logs
Before, on
a9b88f538c74d2347444fac60d7289abcf231a50with only the regression test applied:After:
Documentation