You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Nathan-Fenner (via GitHub)" <gi...@apache.org> on 2023/10/31 20:44:57 UTC

[I] Allow `zip` compute kernel to take `Scalar` / `Datum` [arrow-rs]

Nathan-Fenner opened a new issue, #5011:
URL: https://github.com/apache/arrow-rs/issues/5011

   **Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
   
   `zip` currently has the signature:
   
   ```rs
   /// # Arguments
   /// * `mask` - Boolean values used to determine from which array to take the values.
   /// * `truthy` - Values of this array are taken if mask evaluates `true`
   /// * `falsy` - Values of this array are taken if mask evaluates `false`
   pub fn zip(
       mask: &BooleanArray,
       truthy: &dyn Array,
       falsy: &dyn Array,
   ) -> Result<ArrayRef, ArrowError> { ... }
   ```
   
   However, it would be nice to be able to call `zip` where (usually just one of) the arguments might could be scalar, i.e. via `&dyn Datum` (i.e. analogous to `arrow::compute::kernels::numeric::add`):
   
   ```rs
   /// # Arguments
   /// * `mask` - Boolean values used to determine from which array to take the values.
   /// * `truthy` - Values of this array are taken if mask evaluates `true`
   /// * `falsy` - Values of this array are taken if mask evaluates `false`
   pub fn zip(
       mask: &BooleanArray,
       truthy: &dyn Datum, // a `Datum` instead of `Array`
       falsy: &dyn Datum, // a `Datum` instead of `Array`
   ) -> Result<ArrayRef, ArrowError> { ... }
   ```
   
   Currently, a caller with a (possibly) scalar value for one of the arguments needs to essentially implement `zip` from scratch, and requires downcasting the arrays in order to be able to obtain and copy the (singleton) scalar value.
   
   **Describe the solution you'd like**
   
   Update the `zip` function to accept `if_true: &dyn Datum` and `if_false: &dyn Datum` parameters (just like `add`) with logic to copy the values to each output row if needed, or make a new `zip` function which  takes those parameters as the type `&dyn Datum`.
   
   (`mask` does not need to be a `&dyn Datum`, since when the `mask` is a scalar, it is easy to avoid calling `zip` entirely)
   
   **Describe alternatives you've considered**
   
   Manually replicating the `if_true` or `if_false` values into an array prior to calling `.zip` would work, but requires some tedious downcasting to support every type, and is also probably less efficient because it requires constructing (and then probably throwing away) a temporary array of the same value repeated multiple times.
   
   


-- 
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.apache.org

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


Re: [I] Allow `zip` compute kernel to take `Scalar` / `Datum` [arrow-rs]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on issue #5011:
URL: https://github.com/apache/arrow-rs/issues/5011#issuecomment-1878522122

   `label_issue.py` automatically added labels {'arrow'} from #5086


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


Re: [I] Allow `zip` compute kernel to take `Scalar` / `Datum` [arrow-rs]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold closed issue #5011: Allow `zip` compute kernel to take `Scalar` / `Datum` 
URL: https://github.com/apache/arrow-rs/issues/5011


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


Re: [I] Allow `zip` compute kernel to take `Scalar` / `Datum` [arrow-rs]

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on issue #5011:
URL: https://github.com/apache/arrow-rs/issues/5011#issuecomment-1788919899

   This makes sense to me


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