Allow zip
compute kernel to take Scalar
/ Datum
#5011
Labels
arrow
Changes to the arrow crate
enhancement
Any new improvement worthy of a entry in the changelog
help wanted
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
I currently have a
mask: &BooleanArray
,if_true: &dyn Datum
,if_false: &dyn Datum
, and I know thatif_true.data_type() == if_false.data_type()
, and I'd like to callzip(mask, if_true, if_false)
to obtain anArc<dyn Array>
.However,
zip
currently has the signature:Since it accepts
&dyn Array
instead of&dyn Datum
, I can pass in the underlying arrays for each of my datum... but this will crash ifif_true
is a scalar andif_false
is an array (or vice-versa), since in that case they will have different lengths (1 and 300, say).I want to be able to call
zip()
function just likearrow::compute::kernels::numeric::add
, where scalar values will be repeated to matchmask
: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 acceptif_true: &dyn Datum
andif_false: &dyn Datum
parameters (just likeadd
) with logic to copy the values to each output row if needed, or make a newzip
function which takes those parameters as the type&dyn Datum
.(
mask
does not need to be a&dyn Datum
, since when themask
is a scalar, it is easy to avoid callingzip
entirely)Describe alternatives you've considered
Manually replicating the
if_true
orif_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.The text was updated successfully, but these errors were encountered: