ORC-2619: Fix estimateRgEndOffset slop calculation for incompressible data#2620
Open
thexiay wants to merge 1 commit intoapache:mainfrom
Open
ORC-2619: Fix estimateRgEndOffset slop calculation for incompressible data#2620thexiay wants to merge 1 commit intoapache:mainfrom
thexiay wants to merge 1 commit intoapache:mainfrom
Conversation
a9ffd5d to
c52545c
Compare
… data The stretchFactor calculation in estimateRgEndOffset did not account for the 2-byte RLEv2 DIRECT run header. This caused insufficient buffer allocation when data is incompressible, leading to 'Buffer size too small' errors. Fix: Include RLE_V2_HEADER_SIZE in the worst-case payload calculation. Add test demonstrating the issue with the old formula.
c52545c to
076e787
Compare
There was a problem hiding this comment.
Pull request overview
Fixes RecordReaderUtils.estimateRgEndOffset slop estimation for compressed streams so worst-case RLEv2 DIRECT runs (including the 2-byte run header) are covered, preventing under-reading near row group boundaries on incompressible data.
Changes:
- Update
estimateRgEndOffsetworst-case sizing to include the RLEv2 DIRECT run header. - Add/adjust tests to exercise the old vs new slop behavior and row-group seeking scenarios.
- Introduce
RLE_V2_HEADER_SIZEconstant and update one existing test formula to match the new sizing.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| java/core/src/java/org/apache/orc/impl/RecordReaderUtils.java | Adjust slop/stretch-factor math for compressed streams; add RLEv2 header-size constant. |
| java/core/src/test/org/apache/orc/impl/TestInStream.java | Add regression test intended to demonstrate failure with the old slop estimate when truncated. |
| java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java | Update test’s local slop computation to include the RLEv2 header size. |
| java/core/src/test/org/apache/orc/impl/TestOrcLargeStripe.java | Add integration-style test covering seeking/filtering across row-group boundaries with ZLIB. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+220
to
+222
| // RLEv2 DIRECT runs can need a 2-byte header in addition to their value payload. | ||
| int maxRleDirectRunSize = MAX_VALUES_LENGTH * MAX_BYTE_WIDTH + 2; | ||
| int stretchFactor = 2 + (maxRleDirectRunSize - 1) / bufferSize; |
| static final int MAX_BYTE_WIDTH = | ||
| SerializationUtils.decodeBitWidth(SerializationUtils.FixedBitSizes.SIXTYFOUR.ordinal()) / 8; | ||
| // RLEv2 DIRECT run header size in bytes | ||
| public static final int RLE_V2_HEADER_SIZE = 2; |
Comment on lines
+1018
to
+1022
| final int chunkSize = OutStream.HEADER_SIZE + bufferSize; | ||
| final int nextGroupOffset = bufferSize; | ||
| final int oldStretchFactor = | ||
| 2 + (MAX_VALUES_LENGTH * MAX_BYTE_WIDTH - 1) / bufferSize; | ||
| final int oldEstimatedEnd = nextGroupOffset + oldStretchFactor * chunkSize; |
Comment on lines
+1051
to
+1052
| offset += stream.read( | ||
| rleDirectRun, offset, rleDirectRun.length - offset); |
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 changes were proposed in this pull request?
Fix the
estimateRgEndOffsetslop calculation inRecordReaderUtils.javato account for the 2-byte RLEv2 DIRECT run header.Problem
The old formula:
only considers the value payload (512 * 8 = 4096 bytes) but ignores the 2-byte RLE header. For
bufferSize = 1024, this givesstretchFactor = 5, which is one block short when data is incompressible.Fix
This correctly yields
stretchFactor = 6, ensuring enough compressed blocks are allocated.How was this patch tested?
Added
testTruncatedRleV2DirectRunAtEstimatedEndFailsinTestInStream.javathat:IllegalArgumentException: Buffer size too smallThis proves the old slop estimation was insufficient.
Closes #2619