Skip to content

GH-3988: Expose per-column-chunk uncompressed size via PageReader - #3990

Open
wangyum wants to merge 4 commits into
apache:masterfrom
wangyum:expose-pagereader-uncompressed-size
Open

wangyum wants to merge 4 commits into
apache:masterfrom
wangyum:expose-pagereader-uncompressed-size

Conversation

@wangyum

@wangyum wangyum commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Rationale

See #3988 for the full writeup. PageReader exposes getTotalValueCount() but not a column chunk's total uncompressed byte size, even though ColumnChunkPageReadStore.ColumnChunkPageReader already sums page value counts in its constructor and can just as easily sum page uncompressed sizes in the same loop.

Changes

  • PageReader: add default 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 accumulating DataPage#getUncompressedSize() alongside the existing valueCount accumulation. 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 with getTotalValueCount(), 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 Vectorized and SQL Parquet MR cases), comparing master (baseline, no GH-3988) against this change plus a corresponding reader-side patch that pre-sizes vectorized batch buffers using getTotalValueCount() + getTotalUncompressedSize(). Full run: https://github.com/wangyum/spark/actions/runs/45559891815

Baseline (no GH-3988) Feature (GH-3988 + reader patch)
SQL Parquet Vectorized, Best 2541 ms 2048 ms (-19%)
SQL Parquet Vectorized, Avg ± Stdev 2549 ± 10 ms 2214 ± 235 ms (-13%)
SQL Parquet MR, Best 1535 ms 1477 ms
SQL Parquet MR, Avg ± Stdev 1583 ± 68 ms 1524 ± 67 ms

The 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:

  • Vectorized is still slower than MR after the patch (2048 ms vs 1477 ms) — nowhere near the ~3x gap cited in Expose per-column-chunk uncompressed size via PageReader.getUncompressedSize() #3988. This narrows the gap, it doesn't close it.
  • The feature run's stdev (235 ms) is far higher than baseline's (10 ms), so the -19%/-13% deltas come from one noisy run; the "best" numbers in particular are likely optimistic.
  • Run order was feature-then-baseline, so baseline ran on a warmer/more-contended machine — if anything this likely understates the real improvement rather than overstating it.

Will follow up with a lower-variance run before merge; sharing directional numbers now.

Testing

Ran TestColumnChunkPageReadStore and TestParquetWriter — both pass. spotless:check passes.

Note: I verified this applies cleanly to current master and 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 local thrift (0.22.0) is older than what parquet-format-structures now 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

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() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sum of the uncompressed sizes of the (data) pages this reader will yield

This seems to be inconsistent with similar methods above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
wangyum force-pushed the expose-pagereader-uncompressed-size branch from c6673b8 to bbb5325 Compare November 25, 2026 07:58
ParquetReadOptions lives in parquet-hadoop, which parquet-column does
not depend on, so the javadoc tool can't resolve an {@link} to it when
building parquet-column's javadoc in isolation. Use {@code} instead,
since this is just an illustrative reference, not a real cross-link.
long uncompressed = 0;
for (DataPage p : compressedPages) {
count += p.getValueCount();
uncompressed += p.getUncompressedSize();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose per-column-chunk uncompressed size via PageReader.getUncompressedSize()

2 participants