Repository navigation
Description
Is your feature request related to a problem or challenge?
arrow-rs adds Array::to_arc in apache/arrow-rs#12420, and it is expected to ship in arrow 60.3.0 or 61.0.0. It returns an ArrayRef that shares the buffers of a &dyn Array. When the &dyn Array is an &ArrayRef, it returns a new reference to the same allocation.
DataFusion has four places outside tests that turn a &dyn Array into an ArrayRef with a workaround:
make_array(array.to_data())innormalize_nested_float_zero:datafusion/datafusion/physical-expr-common/src/datum.rs
Lines 128 to 131 in dbb98de
fn normalize_nested_float_zero(array: &dyn Array) -> Option<ArrayRef> { has_float_leaf(array.data_type()) .then(|| float_semantics::normalize(make_array(array.to_data()))) } make_array(v.to_data())inArrayStaticFilter::contains:datafusion/datafusion/physical-expr/src/expressions/in_list/array_static_filter.rs
Line 132 in dbb98de
let normalized = float_semantics::normalize(make_array(v.to_data())); truthy.slice(0, truthy.len())in the all-true fast path ofscatter:datafusion/datafusion/physical-expr-common/src/utils.rs
Lines 80 to 82 in dbb98de
if mask.null_count() == 0 && !mask.has_false() { return Ok(truthy.slice(0, truthy.len())); } make_array(dictionary.keys().to_data())inColumnSize::new:make_array(dictionary.keys().to_data()),
make_array(x.to_data()) builds an ArrayData and then rebuilds a typed array from it, and nested types repeat that for every child. slice(0, len) recounts the null buffer's nulls and re-slices the children of nested types. to_arc clones an arrow-rs array into a new Arc, and for an ArrayRef it only increments the reference count.
Describe the solution you'd like
After DataFusion upgrades to an arrow release that includes Array::to_arc, replace each workaround above with x.to_arc().
Describe alternatives you've considered
We could keep the workarounds. They return equal arrays but do more work per call.
Additional context
The same arrow-rs PR switches arrow's own cast, concat, nullif, and shift from these workarounds to to_arc.
Activity