ritchie46 commented on a change in pull request #9402:
URL: https://github.com/apache/arrow/pull/9402#discussion_r570767432
##########
File path: rust/arrow/src/compute/kernels/cast.rs
##########
@@ -1175,6 +1254,76 @@ where
Ok(Arc::new(b.finish()))
}
+/// Cast the container type of List/Largelist array but not the inner types.
+/// This function can leave the value data intact and only has to cast the
offset dtypes.
+fn cast_list_container<OffsetSizeFrom, OffsetSizeTo>(array: &ArrayRef) ->
Result<ArrayRef>
+where
+ OffsetSizeFrom: OffsetSizeTrait + ToPrimitive,
+ OffsetSizeTo: OffsetSizeTrait + NumCast,
+{
+ let data = array.data_ref();
+ // the value data stored by the list
+ let value_data = data.child_data()[0].clone();
+
+ let out_dtype = match array.data_type() {
+ DataType::List(value_type) => {
+ assert_eq!(
+ std::mem::size_of::<OffsetSizeFrom>(),
+ std::mem::size_of::<i32>()
+ );
+ assert_eq!(
+ std::mem::size_of::<OffsetSizeTo>(),
+ std::mem::size_of::<i64>()
+ );
+ DataType::LargeList(value_type.clone())
+ }
+ DataType::LargeList(value_type) => {
+ assert_eq!(
+ std::mem::size_of::<OffsetSizeFrom>(),
+ std::mem::size_of::<i64>()
+ );
+ assert_eq!(
+ std::mem::size_of::<OffsetSizeTo>(),
+ std::mem::size_of::<i32>()
+ );
+ if value_data.len() > i32::MAX as usize {
+ return Err(ArrowError::ComputeError(
+ "LargeList too large to cast to List".into(),
+ ));
+ }
+ DataType::List(value_type.clone())
+ }
+ // implementation error
+ _ => unreachable!(),
+ };
+
+ // the offsets
+ // SAFETY
+ // We asserted the correct size of OffsetSizeFrom above.
+ let offsets = unsafe { data.buffers()[0].typed_data::<OffsetSizeFrom>() };
Review comment:
Ah, I was not aware of that function, nice! I had to change the
visibility from `pub (super)` to pub (crate)`. May also be a nice method for
the public API.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]