You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/19 20:07:44 UTC

[GitHub] [arrow-rs] alamb commented on a diff in pull request #3326: Provide `into_builder` for bytearray

alamb commented on code in PR #3326:
URL: https://github.com/apache/arrow-rs/pull/3326#discussion_r1052593539


##########
arrow-array/src/array/string_array.rs:
##########
@@ -697,4 +698,40 @@ mod tests {
         assert_eq!(string.len(), 0);
         assert_eq!(string.value_offsets(), &[0]);
     }
+
+    #[test]
+    fn test_into_builder() {
+        let array: StringArray = vec!["hello", "arrow"].into();
+
+        // Modify values
+        let mut builder = array.into_builder().unwrap();
+
+        let (offset_slice, value_slice, _) = builder.slices_mut();
+
+        assert_eq!(offset_slice, &[0, 5, 10]);
+
+        let expected_slice = "helloarrow".as_bytes();
+        assert_eq!(value_slice, expected_slice);
+
+        value_slice[0] = 'H'.as_();
+        value_slice[1] = 'E'.as_();
+        value_slice[2] = 'L'.as_();
+        value_slice[3] = 'L'.as_();
+        value_slice[4] = 'O'.as_();
+
+        let expected: StringArray = vec!["HELLO", "arrow"].into();
+        let array = builder.finish();
+        assert_eq!(expected, array);
+
+        // Modify offsets
+        let mut builder = array.into_builder().unwrap();
+
+        let (offset_slice, _, _) = builder.slices_mut();
+
+        offset_slice[1] = 7;
+
+        let expected: StringArray = vec!["HELLOar", "row"].into();
+        let array = builder.finish();
+        assert_eq!(expected, array);

Review Comment:
   I recommend at least one test that `into_builder()` returns Err() if the reference has been shared
   
   



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org