alamb commented on a change in pull request #1188:
URL: https://github.com/apache/arrow-rs/pull/1188#discussion_r786112854



##########
File path: arrow/src/array/array_binary.rs
##########
@@ -171,6 +159,42 @@ impl<OffsetSize: BinaryOffsetSizeTrait> 
GenericBinaryArray<OffsetSize> {
         let data = unsafe { builder.build_unchecked() };
         Self::from(data)
     }
+
+    /// Creates a `GenericBinaryArray` based on an iterator of values without 
nulls
+    pub fn from_iter_values<Ptr, I>(iter: I) -> Self
+    where
+        Ptr: AsRef<[u8]>,
+        I: IntoIterator<Item = Ptr>,
+    {
+        let iter = iter.into_iter();
+        let (_, data_len) = iter.size_hint();
+        let data_len = data_len.expect("Iterator must be sized"); // panic if 
no upper bound.
+
+        let mut offsets =
+            MutableBuffer::new((data_len + 1) * 
std::mem::size_of::<OffsetSize>());
+        let mut values = MutableBuffer::new(0);
+
+        let mut length_so_far = OffsetSize::zero();
+        offsets.push(length_so_far);
+
+        for s in iter {
+            let s = s.as_ref();
+            length_so_far += OffsetSize::from_usize(s.len()).unwrap();
+            offsets.push(length_so_far);
+            values.extend_from_slice(s);
+        }
+
+        // iterator size hint may not be correct so compute the actual number 
of offsets
+        assert!(!offsets.is_empty()); // wrote at least one

Review comment:
       👍 




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