You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "pitrou (via GitHub)" <gi...@apache.org> on 2024/02/01 13:48:19 UTC

Re: [PR] PARQUET-2423: [C++][Parquet] Avoid allocating buffer obeject in RecordReader's SkipRecords [arrow]

pitrou commented on code in PR #39818:
URL: https://github.com/apache/arrow/pull/39818#discussion_r1474502179


##########
cpp/src/parquet/column_reader.cc:
##########
@@ -1478,16 +1480,29 @@ class TypedRecordReader : public TypedColumnReaderImpl<DType>,
     // We skipped the levels by incrementing 'levels_position_'. For values
     // we do not have a buffer, so we need to read them and throw them away.
     // First we need to figure out how many present/not-null values there are.
-    std::shared_ptr<::arrow::ResizableBuffer> valid_bits;
-    valid_bits = AllocateBuffer(this->pool_);
-    PARQUET_THROW_NOT_OK(valid_bits->Resize(bit_util::BytesForBits(skipped_records),
-                                            /*shrink_to_fit=*/true));
+    int64_t buffer_size = bit_util::BytesForBits(skipped_records);
+    if (valid_bits_for_skip_ == nullptr) {
+      valid_bits_for_skip_ = AllocateBuffer(this->pool_);
+    }
+    if (buffer_size > valid_bits_for_skip_->size()) {

Review Comment:
   > One question is how can the [skipped_records](https://github.com/apache/arrow/blob/main/cpp/src/parquet/column_reader.cc#L1473) for `SkipRecordsInBufferNonRepeated` ever exceed [kMinLevelBatchSize](https://github.com/apache/arrow/blob/main/cpp/src/parquet/column_reader.cc#L1369) (i.e., 1024)?
   
   Why not? You can add an assertion to check this with the test suite.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org