Skip to content

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

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

wangyum wants to merge 2 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.

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

wangyum and others added 2 commits November 23, 2026 17:12
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
…, 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.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* 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?

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