ritchie46 commented on a change in pull request #9526:
URL: https://github.com/apache/arrow/pull/9526#discussion_r579666318



##########
File path: rust/arrow/src/compute/kernels/cast.rs
##########
@@ -1297,6 +1301,57 @@ fn cast_list_inner<OffsetSize: OffsetSizeTrait>(
     Ok(Arc::new(list) as ArrayRef)
 }
 
+/// Helper function to cast from Utf8 > LargeUtf8 and vice versa. If the 
LargeUtf8 it too large for
+/// a Utf8 array it will return an Error.
+fn cast_str_container<OffsetSizeFrom, OffsetSizeTo>(array: &dyn Array) -> 
Result<ArrayRef>
+where
+    OffsetSizeFrom: StringOffsetSizeTrait + ToPrimitive,
+    OffsetSizeTo: StringOffsetSizeTrait + NumCast + ArrowNativeType,
+{
+    let str_array = array
+        .as_any()
+        .downcast_ref::<GenericStringArray<OffsetSizeFrom>>()
+        .unwrap();
+    let list_data = array.data();
+    let str_values_buf = str_array.value_data();
+
+    let offsets = unsafe { 
list_data.buffers()[0].typed_data::<OffsetSizeFrom>() };
+
+    let mut offset_builder = BufferBuilder::<OffsetSizeTo>::new(offsets.len());
+    offsets.iter().try_for_each(|offset| {
+        let offset = match OffsetSizeTo::from(*offset) {
+            Some(idx) => idx,
+            None => {
+                return Err(ArrowError::ComputeError(
+                    "large-utf8 array too large to cast to utf8-array".into(),
+                ))
+            }
+        };

Review comment:
       Yes. I missed the clippy warning amongst the many.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to