scovich commented on code in PR #9295:
URL: https://github.com/apache/arrow-rs/pull/9295#discussion_r2748723938


##########
arrow-array/src/array/mod.rs:
##########
@@ -350,12 +413,19 @@ pub unsafe trait Array: std::fmt::Debug + Send + Sync {
 /// A reference-counted reference to a generic `Array`
 pub type ArrayRef = Arc<dyn Array>;
 
-/// Ergonomics: Allow use of an ArrayRef as an `&dyn Array`
+/// Ergonomics: Allow use of an ArrayRef as an `&dyn Array`.
+/// Use [`Array::as_array_ref_opt()`] to recover the original [`ArrayRef`] and
+/// [`downcast_array_ref()`] to downcast to an Arc of some concrete array type.
 unsafe impl Array for ArrayRef {
     fn as_any(&self) -> &dyn Any {
         self.as_ref().as_any()
     }
 
+    fn as_array_ref_opt(&self) -> Option<ArrayRef> {
+        // Recursively unwrap nested Arcs to find the deepest one
+        Some(innermost_array_ref(Cow::Borrowed(self)))

Review Comment:
   I tried removing `impl Array for Arc<dyn Array>` and the biggest problem is 
that `Scalar<ArrayRef>` stops working. It's not immediately clear whether/how 
to fix that. In particular, there's no obvious replacement for 
`Scalar::new(new_null_array(...))`. 
   
   Other smaller messes include:
   * Quite a few call sites that call `Arc::new(<expression returning 
ArrayRef>) as ArrayRef` (there's that wrapping!)
   * A surprising number of calls to `<ArrayRef as Array>::shrink_to_fit()` 
(fake-mutable, no-op)
   * Lots of calls to `<ArrayRef as Array>::into_data()` (fake-mutable, 
equivalent to `Array::to_data`)
   * A lot of code that has an `ArrayRef` or `&ArrayRef`, and which lacks the 
necessary `.as_ref()` call. Mostly unit tests.
   * Missing `impl Datum for ArrayRef`
   
   Just getting arrow-rs to compile without it was an impressive amount of 
churn:
   ```
    82 files changed, 883 insertions(+), 732 deletions(-)
   ```



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