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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]