mapleFU commented on code in PR #39807:
URL: https://github.com/apache/arrow/pull/39807#discussion_r1532217813


##########
cpp/src/arrow/io/compressed.cc:
##########
@@ -261,16 +263,38 @@ class CompressedInputStream::Impl {
     }
   }
 
-  bool closed() { return !is_open_; }
+  bool closed() const { return !is_open_; }
 
   Result<int64_t> Tell() const { return total_pos_; }
 
   // Read compressed data if necessary
   Status EnsureCompressedData() {
     int64_t compressed_avail = compressed_ ? compressed_->size() - 
compressed_pos_ : 0;
     if (compressed_avail == 0) {
-      // No compressed data available, read a full chunk
-      ARROW_ASSIGN_OR_RAISE(compressed_, raw_->Read(kChunkSize));
+      // Ensure compressed_ buffer is allocated with kChunkSize.
+      if (!supports_zero_copy_from_raw_) {
+        if (compressed_for_non_zero_copy_ == nullptr) {
+          ARROW_ASSIGN_OR_RAISE(compressed_for_non_zero_copy_,
+                                AllocateResizableBuffer(kChunkSize, pool_));
+        } else if (compressed_for_non_zero_copy_->size() != kChunkSize) {
+          RETURN_NOT_OK(
+              compressed_for_non_zero_copy_->Resize(kChunkSize, 
/*shrink_to_fit=*/false));
+        }
+        // set compressed_ to nullptr to avoid `compressed_for_non_zero_copy_` 
being
+        // referenced twice, which would making it "immutable".

Review Comment:
   Aha, previously when I read some code of buffer, I found they check the 
buffer is not multiple-referenced, maybe I confused the code here.



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