Rich-T-kid commented on code in PR #12149:
URL: https://github.com/apache/arrow-rs/pull/12149#discussion_r4570967856
##########
arrow-array/src/array/byte_array.rs:
##########
@@ -717,4 +759,71 @@ mod tests {
fn create_repeated_i32_offset_overflow_2() {
let _arr = BinaryArray::new_repeated(b"hello", ((i32::MAX as usize) /
"hello".len()) + 1);
}
+
+ #[test]
+ fn try_new_repeated() {
+ // StringArray with multiple elements
+ let arr = StringArray::try_new_repeated("abc", 4).unwrap();
+ assert_eq!(arr.len(), 4);
+ assert_eq!(arr.null_count(), 0);
+ for i in 0..4 {
+ assert_eq!(arr.value(i), "abc");
+ }
+ assert_eq!(arr.value_offsets(), &[0, 3, 6, 9, 12]);
+
+ // BinaryArray with multiple elements
+ let arr = BinaryArray::try_new_repeated(b"\x00\x01\xff", 3).unwrap();
+ assert_eq!(arr.len(), 3);
+ assert_eq!(arr.null_count(), 0);
+ for i in 0..3 {
+ assert_eq!(arr.value(i), b"\x00\x01\xff");
+ }
+ assert_eq!(arr.value_offsets(), &[0, 3, 6, 9]);
+
+ // LargeStringArray with 64-bit offsets
+ let arr = LargeStringArray::try_new_repeated("xyz", 3).unwrap();
+ assert_eq!(arr.len(), 3);
+ assert_eq!(arr.null_count(), 0);
+ assert_eq!(arr.value_offsets(), &[0i64, 3, 6, 9]);
Review Comment:
we dont need these seperate cases because they all use the exact same code
path in `GenericByteArray::try_new_repeated`. lets just keep the binary array
one.
##########
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");
Review Comment:
super nit: maybe the doc comment should showcase how all 3 elements are the
same
--
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]