Rich-T-kid commented on code in PR #12149:
URL: https://github.com/apache/arrow-rs/pull/12149#discussion_r4556593921


##########
arrow-array/src/array/byte_array.rs:
##########
@@ -200,6 +203,44 @@ impl<T: ByteArrayType> GenericByteArray<T> {
         }
     }
 
+    /// Create a new [`GenericByteArray`] where `value` is repeated 
`repeat_count` times.
+    ///
+    /// # Errors
+    ///
+    /// Returns an error if value's length multiplied by `repeat_count` 
overflows `usize`
+    /// or exceeds `T::Offset::MAX`.
+    ///
+    /// # Example
+    /// ```
+    /// # use arrow_array::{Array, StringArray};
+    /// let array = StringArray::try_new_repeated("hello", 3).unwrap();
+    /// assert_eq!(array.len(), 3);
+    /// assert_eq!(array.value(0), "hello");
+    /// ```
+    pub fn try_new_repeated(
+        value: impl AsRef<T::Native>,
+        repeat_count: usize,
+    ) -> Result<Self, ArrowError> {
+        let s: &[u8] = value.as_ref().as_ref();
+        let value_offsets = OffsetBuffer::try_from_repeated_length(s.len(), 
repeat_count)
+            .map_err(|err| 
ArrowError::OffsetOverflowError(err.value().unwrap_or(usize::MAX)))?;

Review Comment:
   this seems real



##########
arrow-array/src/array/byte_array.rs:
##########
@@ -717,4 +759,178 @@ mod tests {
     fn create_repeated_i32_offset_overflow_2() {
         let _arr = BinaryArray::new_repeated(b"hello", ((i32::MAX as usize) / 
"hello".len()) + 1);
     }
+

Review Comment:
   we do not need 6 new test for this new method. I think testing the happy 
path as well as the overflow path should be enough.



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