Copilot commented on code in PR #55856:
URL: https://github.com/apache/arrow/pull/55856#discussion_r4738658542
##########
cpp/src/parquet/column_writer.cc:
##########
@@ -1093,17 +1094,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));
Review Comment:
`page_buffer` can alias `compressor_temp_buffer_` (when `page_is_compressed`
and `levels_size == 0`). This is only safe if the non-buffered path *always*
serializes the page payload synchronously before the compression temp buffer is
reused. If serialization can be deferred (even indirectly), later compressions
could overwrite the bytes backing this page. Consider making the lifetime
guarantee explicit (e.g., comment + DCHECK around the write), or ensuring
stability by detaching the compression output buffer for the page (e.g.,
swap/replace the temp buffer for subsequent compressions) or falling back to an
owning copy in the compressed + unbuffered case.
##########
cpp/src/parquet/column_writer.cc:
##########
@@ -1066,16 +1066,17 @@ 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;
+ const bool buffer_page = has_dictionary_ && !fallback_;
+ const int64_t levels_size = definition_levels_rle_size +
repetition_levels_rle_size;
+ // Buffered pages need their own payload since the compression buffer is
reused.
Review Comment:
The prior code had a clear explanation of when/why pages are buffered vs
written eagerly. With the new `buffer_page` flag, it would help to
restore/extend that explanation here to document the key invariant this
refactor relies on: when `!buffer_page && levels_size == 0`, `page_buffer` may
alias an existing buffer and must be consumed immediately. Making that contract
explicit will help prevent future changes (e.g., deferred writes) from
reintroducing subtle lifetime issues.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]