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
| * 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() { |
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?
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.
c6673b8 to
bbb5325
Compare
| long uncompressed = 0; | ||
| for (DataPage p : compressedPages) { | ||
| count += p.getValueCount(); | ||
| uncompressed += p.getUncompressedSize(); |
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.
There was a problem hiding this comment.
Good catch — fixed in c86b7be. getTotalUncompressedSize() now returns -1 as soon as any page reports a negative size, while getTotalValueCount() keeps counting normally. Added a mixed-page test covering this.
…size is negative Page header sizes are unvalidated file metadata. Blindly summing them let a single negative (corrupt or malicious) page cancel out other pages' legitimate sizes, producing a wrong-but-plausible total instead of the documented -1 "unknown" sentinel. getTotalValueCount() is unaffected and keeps counting normally.
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