You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ScalarValue::try_from_array holds onto input array for Struct, Lists types #15205
ScalarValue::try_from_array are used in areas such as accumulators.
Currently arrowslice is used for Struct/Union/List types, causing accumulators holding onto the original arrays (rather than a single value), and thus higher memory usage.
To Reproduce
Create an (struct / list type) array of size n and use ScalarValue::try_from_array to convert it into a ScalarValue.
Expected behavior
Value is copied into a new Array or there would be needing efficient way of representing the scalar value.
Memory usage should be corresponding to a single value rather than the full input array.
changed the title [-]`ScalarValue::try_from_array` holds onto input array for Struct, Union, Lists types[/-][+]`ScalarValue::try_from_array` holds onto input array for Struct, Lists types[/+]on Mar 13, 2025
it seems that there's no direct way to deep copy array in arrow?
so I tested the following code. it seems that it works.
let a = array.slice(index,1);// copylet data = a.to_data();letmut copy = MutableArrayData::new(vec![&data],true, data.len());
copy.extend(0,0, data.len());let a = make_array(copy.freeze());Self::Struct(Arc::new(a.as_struct().to_owned()))
But I'm wondering whether it's better to provide a deep copy method for ScalarValue rather than modify try_from_array.
then we can just copy the scalar value when it's needed since deep copy is expensive.
In this way, the developer still has the option to just use the ScalarValue::try_from_arrayas is without any side effects of recopying memory and possible performance impact.
If reducing memory footprint is really needed, a compact() call can be made explicitly.
Activity
[-]`ScalarValue::try_from_array` holds onto input array for Struct, Union, Lists types[/-][+]`ScalarValue::try_from_array` holds onto input array for Struct, Lists types[/+]chenkovsky commentedon Mar 16, 2025
take
chenkovsky commentedon Mar 18, 2025
Hi, @Dandandan .
it seems that there's no direct way to deep copy array in arrow?
so I tested the following code. it seems that it works.
But I'm wondering whether it's better to provide a deep copy method for ScalarValue rather than modify try_from_array.
then we can just copy the scalar value when it's needed since deep copy is expensive.
bert-beyondloops commentedon May 21, 2026
I personally would go for the fix behind the compact() functionality on ScalarValue
See #21928
In this way, the developer still has the option to just use the
ScalarValue::try_from_arrayas is without any side effects of recopying memory and possible performance impact.If reducing memory footprint is really needed, a
compact()call can be made explicitly.