emilk commented on code in PR #6790:
URL: https://github.com/apache/arrow-rs/pull/6790#discussion_r1856881778


##########
arrow-array/src/array/mod.rs:
##########
@@ -365,6 +368,16 @@ impl Array for ArrayRef {
         self.as_ref().is_empty()
     }
 
+    fn shrink_to_fit(&mut self) {
+        if let Some(slf) = Arc::get_mut(self) {
+            slf.shrink_to_fit();
+        } else {
+            // TODO(emilk): clone the contents and shrink that.
+            // This can be accomplished if we add `trait Array { fn 
clone(&self) -> Box<Array>>; }`.
+            // Or we clone using `let clone = self.slice(0, self.len());` and 
hope that the returned `ArrayRef` is not shared.

Review Comment:
   I think any of the following three approaches makes sense here:
   
   ## Do nothing
   The current approach. If the `ArrayRef` is shared, then we cannot free up 
memory.
   
   In many ways this makes sense, and I'd be fine with it. We can also start 
here and improve it later.
   
   ## Clone using `slice`
   ```rs
   let mut clone = self.slice(0, self.len());
   if let Some(slf) = Arc::get_mut(&mut clone) {
       clone.shrink_to_fit();
   } else {
       // This would be highly unlikely
   }
   clone
   ```
   
   ## Clone using a new trait method
   Add
   ``` rs
   trait Array {
       fn clone(&self) -> Box<dyn Array>;
   }
   (and implement it everywhere)
   ```
   and then call
   ```rs
   let mut clone = Array::clone(self);
   clone.shrink_to_fit();
   Arc::new(clone)
   ```



##########
arrow-array/src/array/mod.rs:
##########
@@ -365,6 +368,16 @@ impl Array for ArrayRef {
         self.as_ref().is_empty()
     }
 
+    fn shrink_to_fit(&mut self) {
+        if let Some(slf) = Arc::get_mut(self) {
+            slf.shrink_to_fit();
+        } else {
+            // TODO(emilk): clone the contents and shrink that.
+            // This can be accomplished if we add `trait Array { fn 
clone(&self) -> Box<Array>>; }`.
+            // Or we clone using `let clone = self.slice(0, self.len());` and 
hope that the returned `ArrayRef` is not shared.

Review Comment:
   I think any of the following three approaches makes sense here:
   
   ## Do nothing
   The current approach. If the `ArrayRef` is shared, then we cannot free up 
memory.
   
   In many ways this makes sense, and I'd be fine with it. We can also start 
here and improve it later.
   
   ## Clone using `slice`
   ```rs
   let mut clone = self.slice(0, self.len());
   if let Some(slf) = Arc::get_mut(&mut clone) {
       clone.shrink_to_fit();
   } else {
       // This would be highly unlikely, and fine
   }
   clone
   ```
   
   ## Clone using a new trait method
   Add
   ``` rs
   trait Array {
       fn clone(&self) -> Box<dyn Array>;
   }
   (and implement it everywhere)
   ```
   and then call
   ```rs
   let mut clone = Array::clone(self);
   clone.shrink_to_fit();
   Arc::new(clone)
   ```



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