HaoYang670 commented on code in PR #3168:
URL: https://github.com/apache/arrow-rs/pull/3168#discussion_r1030986250


##########
arrow-array/src/array/string_array.rs:
##########
@@ -216,8 +216,19 @@ impl<OffsetSize: OffsetSizeTrait> 
From<GenericBinaryArray<OffsetSize>>
     for GenericStringArray<OffsetSize>
 {
     fn from(v: GenericBinaryArray<OffsetSize>) -> Self {
+        let offsets = v.value_offsets();
+        let values = v.data().buffers()[1].as_ref();
+
+        // We only need to validate that all values are valid UTF-8
+        let validated = std::str::from_utf8(values).unwrap();
+        for offset in offsets.iter() {
+            assert!(validated.is_char_boundary(offset.as_usize()))
+        }
+
         let builder = v.into_data().into_builder().data_type(Self::DATA_TYPE);
-        Self::from(builder.build().unwrap())
+        // SAFETY:
+        // Validated UTF-8 above

Review Comment:
   👍
   How much performance improvement can we get?



-- 
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]

Reply via email to