You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/15 12:49:41 UTC

[GitHub] [arrow-rs] alamb opened a new issue #558: Make compute kernels easier to use by taking `&ArrayRef` and downcasting internally

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

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



[GitHub] [arrow-rs] alamb commented on issue #558: Make compute kernels easier to use by taking `&ArrayRef` and downcasting internally

Posted by GitBox <gi...@apache.org>.
alamb commented on issue #558:
URL: https://github.com/apache/arrow-rs/issues/558#issuecomment-880670906


   Or maybe the signature could be something like 
   
   ```rust
   fn add(left: A, right: A) -> ArrayRef 
   where
     A: AsRef<dyn Array>
   ```
   
   So that we could take either an `&ArrayRef` or `&dyn Array` directly


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