alamb opened a new issue #558:
URL: https://github.com/apache/arrow-rs/issues/558


   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   I would like to do arithmetic on temporal arrys like 
`TimestampNanosecondArray`
   
   https://docs.rs/arrow/4.4.0/arrow/compute/kernels/arithmetic/fn.add.html
   
   The current compute kernels have the following signatures:
   
   ```rust
   pub fn add<T>(
       left: &PrimitiveArray<T>, 
       right: &PrimitiveArray<T>
   ) -> Result<PrimitiveArray<T>> 
   ...
   ```
   
   So if I have two `ArrayRefs` (aka `Arc<dyn Array>`) I am forced to downcast 
them to specific known types like
   ```rust
   let left = left.as_any().downcast_ref<TimestampNanosecondArray>().unwrap();
   let right = right.as_any().downcast_ref<DurationArray>().unwrap();
   
   let result = compute::add(left, right).unwrap();
   ```
   
   
   However, the cast kernel is much easier to use as it does this type dispatch 
/ downcasting internally for me:
   
   ```rust
   let cast_result = compute::cast(&left, DataType::Int32)`
   ```
   
   **Describe the solution you'd like**
   I would like for the `add` (and other compute kernels) to take a `&ArrayRef` 
as argument and then do any type matching / downcasting necessary internally, 
so I, as a user, don't have to think about it
   
   **Describe alternatives you've considered**
   An alternate is to take an `&dyn Array` and avoid the need for wrapping the 
array in an `Arc` -- however, given the prevalence of `ArrayRef` / `Arc` in 
Arrow APIs already I would personally prefer a uniform interface with the 
kernels like `cast` which already take `&ArrayRef`
   
   **Additional context**
   There is additional discussion and context at 
https://github.com/apache/arrow-rs/issues/527#issuecomment-880649326


-- 
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-unsubscr...@arrow.apache.org

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


Reply via email to