jorisvandenbossche commented on code in PR #38784:
URL: https://github.com/apache/arrow/pull/38784#discussion_r1404616339


##########
cpp/src/parquet/encoding.cc:
##########
@@ -1196,15 +1196,22 @@ struct ArrowBinaryHelper<ByteArrayType> {
         chunk_space_remaining_(::arrow::kBinaryMemoryLimit -
                                acc_->builder->value_data_length()) {}
 
+  // Prepare will reserve the number of entries remaining in the current chunk.
+  // If estimated_data_length is provided, it will also reserve the estimated 
data length,
+  // and the caller should better call `UnsafeAppend` instead of `Append` to 
avoid
+  // double-checking the data length.
   Status Prepare(std::optional<int64_t> estimated_data_length = {}) {
     RETURN_NOT_OK(acc_->builder->Reserve(entries_remaining_));
     if (estimated_data_length.has_value()) {
       RETURN_NOT_OK(acc_->builder->ReserveData(
-          std::min<int64_t>(*estimated_data_length, 
::arrow::kBinaryMemoryLimit)));
+          std::min<int64_t>(*estimated_data_length, 
this->chunk_space_remaining_)));

Review Comment:
   I can confirm that this change actually fixes the regression 
(https://github.com/apache/arrow/issues/38577#issuecomment-1826032128). 
   
   When the decoder/builder is reused (eg reading a second row group or batch 
of a row group), `chunk_space_remaining_` is smaller than `kBinaryMemoryLimit`. 
So if `estimated_data_length` is larger than `chunk_space_remaining_`, we are 
trying to reserve too many values. 



-- 
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]

Reply via email to