dqkqd commented on code in PR #8735:
URL: https://github.com/apache/arrow-rs/pull/8735#discussion_r2556005600
##########
arrow-cast/src/cast/list.rs:
##########
@@ -160,6 +169,70 @@ pub(crate) fn cast_list_values<O: OffsetSizeTrait>(
)?))
}
+/// Helper function to cast a list view to a list
+pub(crate) fn cast_list_view_to_list<O: OffsetSizeTrait>(
+ array: &dyn Array,
+ to: &FieldRef,
+ cast_options: &CastOptions,
+) -> Result<ArrayRef, ArrowError> {
+ let list_view = array.as_list_view::<O>();
+ let list_view_offsets = list_view.offsets();
+ let sizes = list_view.sizes();
+ let source_values = list_view.values();
+
+ // Construct the indices and offsets for the new list array by iterating
over the list view subarrays
+ let mut indices = Vec::with_capacity(list_view.values().len());
+ let mut offsets = Vec::with_capacity(list_view.len() + 1);
+ // Add the offset for the first subarray
+ offsets.push(O::usize_as(0));
+ for i in 0..list_view.len() {
+ // For each subarray, add the indices of the values to take
+ let offset = list_view_offsets[i].as_usize();
+ let size = sizes[i].as_usize();
+ let end = offset + size;
+ for j in offset..end {
+ indices.push(j as i32);
+ }
+ // Add the offset for the next subarray
+ offsets.push(O::usize_as(indices.len()));
+ }
+
+ // Take the values from the source values using the indices, creating a
new array
+ let values = arrow_select::take::take(source_values,
&Int32Array::from(indices), None)?;
Review Comment:
> I believe MutableArrayData is not as performant as take. Since we know
upfront what indices we need, I think take is the right call here.
Thank you, I did not know this. I thought it would be better to just use
`MutableArrayData` because we are manually building the `indicies` anyway.
--
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]