XiangpengHao commented on code in PR #6180:
URL: https://github.com/apache/arrow-rs/pull/6180#discussion_r1702421773
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -2417,6 +2436,37 @@ where
Ok(Arc::new(byte_array_builder.finish()))
}
+/// Specialized function to cast from one `ByteViewType` array to
`ByteArrayType` array.
+/// Equvilent to [`cast_view_to_byte`] but with additional constraint on the
`FROM::Native` type.
+fn cast_slice_view_to_byte<FROM, TO>(array: &dyn Array) -> Result<ArrayRef,
ArrowError>
+where
+ FROM: ByteViewType,
+ TO: ByteArrayType,
+ FROM::Native: AsRef<[u8]>,
+ str: AsRef<TO::Native>,
+{
+ let data = array.to_data();
+ let view_array = GenericByteViewArray::<FROM>::from(data);
+
+ let len = view_array.len();
+ let bytes = view_array
+ .views()
+ .iter()
+ .map(|v| ByteView::from(*v).length as usize)
+ .sum::<usize>();
+
+ let mut byte_array_builder = GenericByteBuilder::<TO>::with_capacity(len,
bytes);
+
+ for val in view_array.iter() {
Review Comment:
One way to do this is to create a BinaryArray first, then cast it to
StringArray if necessary:
https://github.com/apache/arrow-rs/blob/master/arrow-array/src/array/string_array.rs#L76-L82
--
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]