[Iceberg] Fix manifest bounds being padded with trailing 0x00 bytes#38580
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a bug where manifest bounds in Iceberg tables were being incorrectly serialized due to the use of ByteBuffer.array(). This method returns the entire backing array, which often includes trailing zero-initialized bytes when the buffer is over-allocated by encoders. These leaked bytes corrupted the lower bounds, causing query engines to incorrectly prune files during predicate pushdown. The fix ensures that only the relevant content window is copied, and a regression test has been added to verify the fix. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes a bug in SerializableDataFile where ByteBuffer.array() was used to extract data, potentially leaking trailing bytes from the backing array into manifest bounds. A new toByteArray helper method now correctly copies only the active portion of the buffer. A corresponding unit test was added to verify that bounds are copied based on the buffer's limit rather than the backing array's capacity. I have no feedback to provide.
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
R: @ahmedabu98 |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
|
assign set of reviewers |
|
Assigning reviewers: R: @kennknowles for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
ahmedabu98
left a comment
There was a problem hiding this comment.
Great job finding this one. Left one comment
Per review on apache#38580, exercise the real production path that produces the buggy buffer shape (capacity > limit) rather than hand-constructing the buffer. The original synthetic version decoupled the test from JDK/Iceberg encoder behavior, but the bug can't exist if those don't over-allocate, so the decoupling argument doesn't add much.
d9d6ba3 to
0b677ad
Compare
|
Seems like a transient CI failure: |
ahmedabu98
left a comment
There was a problem hiding this comment.
LGTM, thx for fixing this!
Summary
SerializableDataFile.toByteArrayMapusedByteBuffer.array()to extract bound bytes.array()returns the full backing array, ignoring the buffer's[position, limit)content window.Iceberg's Conversions.toByteBuffer delegates to JDK CharsetEncoder.encode(CharBuffer), which sizes its allocation by
(int)(chars * averageBytesPerChar). For UTF-8 the average is 1.1, so a 15-char string lands in a 16-byte buffer with position=0, limit=15, capacity=16. The 16th byte is the zero-initialized tail of the backing array.Reading via
.array()leaks that tail into the byte[] form, and on the return tripByteBuffer.wrap(byte[])treats it as content. The manifest ends up with a lower bound that is strictly greater than the real minimum byte-lexicographically. Query engines using Iceberg metadata for predicate pushdown decidevalue < lower_boundfor any equality filter on that minimum and prune every file, returning 0 rows.Why the bug stays quiet for most queries
All three must hold:
truncate(N)from metrics config, default 16). Below 10, the JDK encoder allocates exact-size buffers; above N, Iceberg trims the string first, so the bound holds a truncated form that a full-value query naturally sorts past.=,IN, etc.).Fix
SerializableDataFile, and asserts the resulting byte[] match the encoded content rather than the inflated backing array.Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.