Nathan-Fenner opened a new pull request, #5086:
URL: https://github.com/apache/arrow-rs/pull/5086
# Which issue does this PR close?
Closes #5011.
# Rationale for this change
The arrow compute kernel function `zip` can now work on scalars, allowing a
scalar value to be "zipped" with another array, repeating the scalar where
needed to fill in the selected spots:
<table>
<thead>
<tr>
<td><b>Before</b></td><td><b>After</b></td>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre>
pub fn zip(
mask: &BooleanArray,
truthy: &dyn Array,
falsy: &dyn Array,
) -> Result<ArrayRef, ArrowError> { ... }
</pre>
</td>
<td>
<pre>
pub fn zip(
mask: &BooleanArray,
truthy: impl Datum,
falsy: impl Datum,
) -> Result<ArrayRef, ArrowError> { ... }
</pre>
</td>
</tr>
</tbody>
</table>
If a `Scalar` value is provided, then it will be copied to fill every spot
specified in the `mask`. Previously, callers would be required to implement
this logic internally to support this.
Since `&dyn Array` already implements `Datum`, existing calls will still
continue to work exactly as they did before, but it is now also possible to
pass in a scalar value.
In addition, `&dyn Datum` now implements `Datum`. This means that `zip` can
be called with the same signature as e.g. `add`, which explicitly ask for `&dyn
Datum`; otherwise, it would not be possible to call `zip` with the same kind of
signature as `add`.
(I think in a future PR, it would be a good idea to change `add`, `sub`, and
all of the other computing kernels to take `impl Datum` parameters instead of
`&dyn Datum` parameters for maximum flexibility and efficiency)
# What changes are included in this PR?
- `zip`'s signature changes from `&dyn Array` to `impl Datum`
- `&dyn Datum` now implements `Datum`
# Are there any user-facing changes?
- `zip` now supports `Scalar`/`Datum` arguments
- `&dyn Datum` now implements `Datum`
--
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]