tustvold commented on code in PR #5922:
URL: https://github.com/apache/arrow-rs/pull/5922#discussion_r1650032966
##########
arrow-array/src/array/byte_view_array.rs:
##########
@@ -429,6 +514,40 @@ impl<T: ByteViewType + ?Sized> From<ArrayData> for
GenericByteViewArray<T> {
}
}
+impl<FROM, V> From<&GenericByteArray<FROM>> for GenericByteViewArray<V>
+where
+ FROM: ByteArrayType,
+ FROM::Offset: OffsetSizeTrait + ToPrimitive,
+ V: ByteViewType,
+ FROM::Native: PartialEq<V::Native>, // this prevent users to convert
between byte and string types.
+{
+ fn from(value: &GenericByteArray<FROM>) -> Self {
+ let byte_array = value;
+ let len = byte_array.len();
+ let str_values_buf = byte_array.values().clone();
+ let offsets = byte_array.offsets();
+
+ let mut views_builder =
GenericByteViewBuilder::<V>::with_capacity(len);
+ let block = views_builder.append_block(str_values_buf);
+ for (i, w) in offsets.windows(2).enumerate() {
+ let offset = w[0].to_u32().unwrap();
+ let end = w[1].to_u32().unwrap();
+ let length = end - offset;
Review Comment:
This should use `as_usize()` to avoid overflowing unnecessarily (we only
care that the length is < u32)
--
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]