rluvaton commented on code in PR #7309: URL: https://github.com/apache/arrow-rs/pull/7309#discussion_r2024328466
########## arrow-array/src/builder/generic_bytes_builder.rs: ########## @@ -593,4 +635,101 @@ mod tests { &["foo".as_bytes(), "bar\n".as_bytes(), "fizbuz".as_bytes()] ) } + + #[test] + fn test_append_array_without_nulls() { + let input = vec![ + "hello", "world", "how", "are", "you", "doing", "today", "I", "am", "doing", "well", + "thank", "you", "for", "asking", + ]; + let arr1 = GenericStringArray::<i32>::from(input[..3].to_vec()); + let arr2 = GenericStringArray::<i32>::from(input[3..7].to_vec()); + let arr3 = GenericStringArray::<i32>::from(input[7..].to_vec()); + + let mut builder = GenericStringBuilder::<i32>::new(); + builder.append_array(&arr1); + builder.append_array(&arr2); + builder.append_array(&arr3); + + let actual = builder.finish(); + let expected = GenericStringArray::<i32>::from(input); + + assert_eq!(actual, expected); + } + + #[test] + fn test_append_array_with_nulls() { + let input = vec![ + Some("hello"), + None, + Some("how"), + None, + None, + None, + None, + Some("I"), + Some("am"), + Some("doing"), + Some("well"), + ]; + let arr1 = GenericStringArray::<i32>::from(input[..3].to_vec()); + let arr2 = GenericStringArray::<i32>::from(input[3..7].to_vec()); + let arr3 = GenericStringArray::<i32>::from(input[7..].to_vec()); + + let mut builder = GenericStringBuilder::<i32>::new(); + builder.append_array(&arr1); + builder.append_array(&arr2); + builder.append_array(&arr3); + + let actual = builder.finish(); + let expected = GenericStringArray::<i32>::from(input); + + assert_eq!(actual, expected); + } + + #[test] + fn test_append_empty_array() { + let arr = GenericStringArray::<i32>::from(Vec::<&str>::new()); + let mut builder = GenericStringBuilder::<i32>::new(); + builder.append_array(&arr); + let result = builder.finish(); + assert_eq!(result.len(), 0); + } + + #[test] + fn test_append_array_with_offset_not_starting_at_0() { + let input = vec![ + Some("hello"), + None, + Some("how"), + None, + None, + None, + None, + Some("I"), + Some("am"), + Some("doing"), + Some("well"), + ]; + let full_array = GenericStringArray::<i32>::from(input); + let sliced = full_array.slice(1, 4); + + assert_ne!(sliced.offsets()[0].as_usize(), 0); + assert_ne!(sliced.offsets().last(), full_array.offsets().last()); + + let mut builder = GenericStringBuilder::<i32>::new(); + builder.append_array(&sliced); + let actual = builder.finish(); + + let expected = GenericStringArray::<i32>::from(vec![None, Some("how"), None, None]); + + println!("actual: {:?}", actual); + println!("expected: {:?}", expected); + assert_eq!(actual, expected); Review Comment: Sorry was for debugging -- 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-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org