Repository navigation
GH-55855: [C++][Parquet] Avoid copying the values buffer for V2 data pages without levels - #55856
Conversation
| ConcatenateBuffers(definition_levels_rle_size, repetition_levels_rle_size, | ||
| compressed_values, combined->mutable_data()); | ||
| std::shared_ptr<Buffer> page_buffer = | ||
| page_is_compressed ? compressor_temp_buffer_ : values; |
There was a problem hiding this comment.
There is an issue here, though I am not sure if it should block this PR.
PageWriter is a pure virtual class with the method signature virtual int64_t WriteDataPage(const DataPage& page) = 0. If a custom class inherits from PageWriter and invokes std::shared_ptr<Buffer> Page::buffer() const { return buffer_; }, it can retrieve a shared_ptr from the const DataPage& page argument.
However, with this change, compressor_temp_buffer_ is written out directly; consequently, downstream components can no longer rely on this shared_ptr remaining valid during the next call to BuildDataPageV2. That said, the fact that const DataPage& page is passed as an argument arguably carries the implicit semantic that the page object might become invalid after the call returns.
There was a problem hiding this comment.
I discovered that BuildDataPageV1 already contained similar code six years ago.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Refactors Parquet V2 data page construction to avoid unnecessary payload copies when pages have no def/rep levels, reducing per-page allocation/copy overhead.
Changes:
- Update
ColumnWriterImpl::BuildDataPageV2to reuse the existing values buffer as the page payload when possible. - Buffer/copy page payload only when levels are present or when pages must be retained for dictionary encoding.
- Refactor and expand multi-page roundtrip tests to cover additional configurations (including V2 + ZSTD paths under
ARROW_WITH_ZSTD).
| File | Description |
|---|---|
| cpp/src/parquet/file_serialize_test.cc | Refactors multi-page roundtrip test into a helper and adds additional scenarios (incl. V2/ZSTD and dictionary toggles). |
| cpp/src/parquet/column_writer.cc | Avoids concatenation/copy when levels aren’t present; only allocates when levels exist or the page must be buffered for dictionary encoding. |
Review effort: Lite
| DataPageV2 page(page_buffer, num_values, null_count, num_rows, encoding_, | ||
| def_levels_byte_length, rep_levels_byte_length, uncompressed_size, | ||
| page_is_compressed, std::move(page_stats), first_row_index, | ||
| std::move(page_size_stats)); |
There was a problem hiding this comment.
This comment was addressed earlier.


Rationale for this change
When a V2 data page has no repetition or definition levels, its values buffer is already the complete payload. Copying it into a separate page buffer adds one allocation and one copy per page.
What changes are included in this PR?
Refactor
BuildDataPageV2.Are these changes tested?
Yes.
Are there any user-facing changes?
No.
Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by: