asubiotto commented on code in PR #8735:
URL: https://github.com/apache/arrow-rs/pull/8735#discussion_r2477613407
##########
arrow-cast/src/cast/list.rs:
##########
@@ -160,6 +169,48 @@ pub(crate) fn cast_list_values<O: OffsetSizeTrait>(
)?))
}
+/// Helper function to cast the values in a list view to a list
+pub(crate) fn cast_list_view_values<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)?;
+
+ // Cast the values to the target data type
+ let values = cast_with_options(&values, to.data_type(), cast_options)?;
Review Comment:
Right, this is necessary if your inner element type is a different type
(e.g. ListView(uint8) -> ListView(utf8)) or whatever
--
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]