jayzhan211 commented on code in PR #4484:
URL: https://github.com/apache/arrow-rs/pull/4484#discussion_r1257644741
##########
arrow-cast/src/cast.rs:
##########
@@ -3680,6 +3682,45 @@ fn cast_primitive_to_list<OffsetSize: OffsetSizeTrait +
NumCast>(
Ok(list_array)
}
+/// Wraps a list array with another list array, using the specified
`OffsetSize`.
+/// This function converts a dynamic array reference to a typed list array,
creates a new list array
+/// with the same elements as the original array, and wraps it with another
list array.
+fn wrap_list_array_with_another_one<OffsetSize: OffsetSizeTrait>(
+ array: &dyn Array,
+) -> Result<ArrayRef, ArrowError> {
+ let array = array.as_list::<OffsetSize>();
+ let array_data_type = array.data_type();
+ let field = Arc::new(Field::new("item", array_data_type.clone(), true));
+ let array_len = array.len();
+ let offsets = OffsetBuffer::<OffsetSize>::from_lengths([array_len]);
+ let values = Arc::new(array.clone()) as ArrayRef;
+ let new_list_array =
+ GenericListArray::<OffsetSize>::new(field, offsets, values, None);
+ Ok(Arc::new(new_list_array))
+}
+
+/// Helper function that casts an Generic list container
+fn cast_list<OffsetSize: OffsetSizeTrait>(
+ array: &dyn Array,
+ to: &Field,
+ to_type: &DataType,
+ cast_options: &CastOptions,
+) -> Result<ArrayRef, ArrowError> {
+ match to.data_type() {
Review Comment:
I assume only casting lower-dimension list to higher_dimension list is
valid, so we don't need to check `array.datatype` but `to_type`. Should we also
support high to low casting?
--
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]