xinlifoobar commented on code in PR #6180:
URL: https://github.com/apache/arrow-rs/pull/6180#discussion_r1703144298
##########
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:
Thanks :). This really works! Benchmark result from my dev machine:
```
cast string view to string
time: [62.413 µs 62.644 µs 62.960 µs]
change: [-11.209% -10.902% -10.567%] (p = 0.00 <
0.05)
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
3 (3.00%) high mild
3 (3.00%) high severe
Benchmarking cast binary view to wide string: Collecting 100 samples in
estimated 5.4525 s (6
cast binary view to wide string
time: [87.806 µs 87.938 µs 88.092 µs]
change: [-34.521% -34.203% -33.887%] (p = 0.00 <
0.05)
Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) high mild
```
--
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]