Repository navigation
Conversation
PageReader exposes getTotalValueCount() but not a column chunk's total uncompressed byte size, even though ColumnChunkPageReadStore already sums page value counts in its constructor and could just as easily sum page uncompressed sizes at the same time. Add a default getUncompressedSize() (-1 if unknown) so existing PageReader implementations are unaffected, and implement it in ColumnChunkPageReadStore. Combined with getTotalValueCount(), this lets callers compute an average uncompressed-bytes-per-value for a whole column chunk before decoding any page, which is useful for pre-sizing per-batch buffers in vectorized readers (e.g. Spark's) ahead of reading binary/string columns with large values. This change has no effect by itself; it only exposes a number ColumnChunkPageReadStore already computes. Fixes apache#3988
wgtmac
reviewed
Nov 25, 2026
| * that allocation (e.g. as {@link org.apache.parquet.ParquetReadOptions#getMaxAllocationSize()} | ||
| * does internally) rather than allocating the full reported size in one call. | ||
| */ | ||
| default long getTotalUncompressedSize() { |
Member
There was a problem hiding this comment.
sum of the uncompressed sizes of the (data) pages this reader will yield
This seems to be inconsistent with similar methods above?
Member
Author
There was a problem hiding this comment.
Good catch — fixed in bbb5325. getTotalValueCount() and getTotalUncompressedSize() are both summed from the same (possibly filtered) page list, so the javadoc should say the same thing about filtering.
…, add tests and doc fixes Deep review found the new PageReader method name collided in spirit with the per-page Page.getUncompressedSize() (used a dozen times in the very same ColumnChunkPageReadStore.java) and broke the interface's own getTotalValueCount() naming convention, as well as the existing ColumnChunkMetaData.getTotalUncompressedSize(). Renamed now while the method is still unreleased, since this would be a breaking change after a release. Also: - Added unit test coverage: an assertion using the existing known-size DataPageV1 fixture, plus a new multi-page summation test. Verified both catch a regression by temporarily breaking the accumulator and confirming they fail, then restoring it and confirming they pass. - Clarified the Javadoc: the value reflects pages this reader will yield (which may be a filtered subset under row-range/column-index filtering), not unconditionally the whole column chunk; only -1 (not any non-positive value) means "unknown", since 0 is a legitimate answer for an empty chunk; and the value is derived from unvalidated page-header metadata, so callers pre-sizing an allocation from it should bound/chunk it rather than allocating the full reported size in one call.
…semantics getTotalValueCount() and getTotalUncompressedSize() are both derived from the same (possibly row-range/column-index filtered) page list, but only the latter's javadoc mentioned that. Update getTotalValueCount() to match.
wangyum
force-pushed
the
expose-pagereader-uncompressed-size
branch
from
November 25, 2026 07:58
c6673b8 to
bbb5325
Compare
wgtmac
reviewed
Nov 25, 2026
| long uncompressed = 0; | ||
| for (DataPage p : compressedPages) { | ||
| count += p.getValueCount(); | ||
| uncompressed += p.getUncompressedSize(); |
Member
There was a problem hiding this comment.
A negative uncompressed page size can cancel out valid pages and leave a plausible total. Please return -1 if any page reports a negative size, keep counting values, and cover the mixed-page case.
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.
Rationale
See #3988 for the full writeup.
PageReaderexposesgetTotalValueCount()but not a column chunk's total uncompressed byte size, even thoughColumnChunkPageReadStore.ColumnChunkPageReaderalready sums page value counts in its constructor and can just as easily sum page uncompressed sizes in the same loop.Changes
PageReader: adddefault long getUncompressedSize() { return -1; }. Being a default method returning a sentinel, this is source- and binary-compatible with existing implementations — checked the other implementors in this repo (CheckParquet251Command,TestStatistics,MemPageReader); none need to change.ColumnChunkPageReadStore: implement it by accumulatingDataPage#getUncompressedSize()alongside the existingvalueCountaccumulation. No extra I/O or computation.This change has no effect by itself — it only exposes a number that's already being computed. The motivating use case is pre-sizing per-batch buffers in vectorized readers (e.g. Spark's
VectorizedColumnReader, see the linked issue for measured results): combined withgetTotalValueCount(), a caller can compute an average uncompressed-bytes-per-value for a whole column chunk before decoding any page, instead of discovering sizes incrementally page by page.Benchmark
Ran Spark's
ParquetReadBenchmark(SQL Parquet VectorizedandSQL Parquet MRcases), comparingmaster(baseline, no GH-3988) against this change plus a corresponding reader-side patch that pre-sizes vectorized batch buffers usinggetTotalValueCount()+getTotalUncompressedSize(). Full run: https://github.com/wangyum/spark/actions/runs/45559891815The non-vectorized MR path never uses this pre-sizing, so its near-flat numbers (best-case delta falls within baseline's own stdev) act as a control — the improvement is isolated to the vectorized path that actually consumes the new API.
Caveats, in the interest of not overselling this:
Will follow up with a lower-variance run before merge; sharing directional numbers now.
Testing
Ran
TestColumnChunkPageReadStoreandTestParquetWriter— both pass.spotless:checkpasses.Note: I verified this applies cleanly to current
masterand re-ran the above tests against a very recent commit before rebasing, but couldn't complete a full local reactor build against the exact current tip because my localthrift(0.22.0) is older than whatparquet-format-structuresnow requires (0.25.0). This change doesn't touch anything thrift-generated, so I don't expect it to matter, but flagging it so CI is the source of truth.Fixes #3988