Repository navigation
GH-55855: [C++][Parquet] Avoid copying the values buffer for V2 data pages without levels #55856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1066,16 +1066,18 @@ void ColumnWriterImpl::BuildDataPageV2(int64_t definition_levels_rle_size, | |
| page_is_compressed = | ||
| (1.0 - static_cast<double>(compressed) / values->size()) >= minimum; | ||
| } | ||
| std::shared_ptr<Buffer> compressed_values = | ||
| (page_is_compressed ? compressor_temp_buffer_ : values); | ||
|
|
||
| // Concatenate uncompressed levels and the possibly compressed values | ||
| int64_t combined_size = | ||
| definition_levels_rle_size + repetition_levels_rle_size + compressed_values->size(); | ||
| std::shared_ptr<ResizableBuffer> combined = AllocateBuffer(allocator_, combined_size); | ||
|
|
||
| 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; | ||
| // Write the page to OutputStream eagerly if there is no dictionary or | ||
| // if dictionary encoding has fallen back to PLAIN. | ||
| const bool buffer_page = has_dictionary_ && !fallback_; | ||
| const int64_t levels_size = definition_levels_rle_size + repetition_levels_rle_size; | ||
| if (levels_size > 0 || buffer_page) { | ||
| auto combined = AllocateBuffer(allocator_, levels_size + page_buffer->size()); | ||
| ConcatenateBuffers(definition_levels_rle_size, repetition_levels_rle_size, | ||
| page_buffer, combined->mutable_data()); | ||
| page_buffer = std::move(combined); | ||
| } | ||
|
|
||
| auto [page_stats, page_size_stats] = GetPageStatistics(); | ||
| page_stats.ApplyStatSizeLimits(properties_->max_statistics_size(descr_->path())); | ||
|
|
@@ -1093,17 +1095,15 @@ void ColumnWriterImpl::BuildDataPageV2(int64_t definition_levels_rle_size, | |
| // here for safety check. | ||
| DCHECK(!page_stats.has_null_count || page_stats.null_count == null_count); | ||
|
|
||
| // Write the page to OutputStream eagerly if there is no dictionary or | ||
| // if dictionary encoding has fallen back to PLAIN | ||
| if (has_dictionary_ && !fallback_) { // Save pages until end of dictionary encoding | ||
| if (buffer_page) { | ||
| std::unique_ptr<DataPage> page_ptr = std::make_unique<DataPageV2>( | ||
| combined, num_values, null_count, num_rows, encoding_, def_levels_byte_length, | ||
| 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)); | ||
| total_compressed_bytes_ += page_ptr->size() + sizeof(format::PageHeader); | ||
| data_pages_.push_back(std::move(page_ptr)); | ||
| } else { | ||
| DataPageV2 page(combined, num_values, null_count, num_rows, encoding_, | ||
| 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)); | ||
|
Comment on lines
+1106
to
1109
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment was addressed earlier. |
||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an issue here, though I am not sure if it should block this PR.
PageWriteris a pure virtual class with the method signaturevirtual int64_t WriteDataPage(const DataPage& page) = 0. If a custom class inherits fromPageWriterand invokesstd::shared_ptr<Buffer> Page::buffer() const { return buffer_; }, it can retrieve ashared_ptrfrom theconst DataPage& pageargument.However, with this change,
compressor_temp_buffer_is written out directly; consequently, downstream components can no longer rely on thisshared_ptrremaining valid during the next call toBuildDataPageV2. That said, the fact thatconst DataPage& pageis passed as an argument arguably carries the implicit semantic that thepageobject might become invalid after the call returns.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I discovered that
BuildDataPageV1already contained similar code six years ago.