From 1e1469f28cfb374a5c809042c6ba18fca59c4def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E7=95=A5?= Date: Sun, 14 Dec 2025 02:55:20 +0800 Subject: [PATCH 1/2] feat: implement append_array for FixedSizeBinaryBuilder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implemented append_array for the builder - extends from buffers in array - ensure value_length is compatible - To #8750 Signed-off-by: 蔡略 --- .../src/builder/fixed_size_binary_builder.rs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/arrow-array/src/builder/fixed_size_binary_builder.rs b/arrow-array/src/builder/fixed_size_binary_builder.rs index 8fd6b72c053b..9bcbfab04fa1 100644 --- a/arrow-array/src/builder/fixed_size_binary_builder.rs +++ b/arrow-array/src/builder/fixed_size_binary_builder.rs @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +use crate::array::Array; use crate::builder::ArrayBuilder; use crate::{ArrayRef, FixedSizeBinaryArray}; use arrow_buffer::Buffer; @@ -101,6 +102,23 @@ impl FixedSizeBinaryBuilder { self.null_buffer_builder.append_n_nulls(n); } + /// Appends all elements in array into the builder. + pub fn append_array(&mut self, array: &FixedSizeBinaryArray) -> Result<(), ArrowError> { + if self.value_length != array.value_length() { + return Err(ArrowError::InvalidArgumentError( + "Cannot append FixedSizeBinaryArray with different value length".to_string(), + )); + } + let buffer = array.value_data(); + self.values_builder.extend_from_slice(buffer); + if let Some(validity) = array.nulls() { + self.null_buffer_builder.append_buffer(validity); + } else { + self.null_buffer_builder.append_n_non_nulls(array.len()); + } + Ok(()) + } + /// Returns the current values buffer as a slice pub fn values_slice(&self) -> &[u8] { self.values_builder.as_slice() @@ -270,4 +288,43 @@ mod tests { fn test_fixed_size_binary_builder_invalid_value_length() { let _ = FixedSizeBinaryBuilder::with_capacity(15, -1); } + + #[test] + fn test_fixed_size_binary_builder_append_array() { + let mut other_builder = FixedSizeBinaryBuilder::with_capacity(3, 5); + other_builder.append_value(b"hello").unwrap(); + other_builder.append_null(); + other_builder.append_value(b"arrow").unwrap(); + let other_array = other_builder.finish(); + + let mut builder = FixedSizeBinaryBuilder::with_capacity(3, 5); + builder.append_array(&other_array).unwrap(); + // Append again to test if breaks when appending multiple times + builder.append_array(&other_array).unwrap(); + let array = builder.finish(); + + assert_eq!(array.value_length(), other_array.value_length()); + assert_eq!(&DataType::FixedSizeBinary(5), array.data_type()); + assert_eq!(6, array.len()); + assert_eq!(2, array.null_count()); + for i in 0..6 { + assert_eq!(i * 5, array.value_offset(i as usize)); + } + + assert_eq!(b"hello", array.value(0)); + assert_eq!(b"hello", array.value(3)); + assert_eq!(b"arrow", array.value(5)); + assert!(array.is_null(1)); + assert!(array.is_null(4)); + } + + #[test] + #[should_panic(expected = "Cannot append FixedSizeBinaryArray with different value length")] + fn test_fixed_size_binary_builder_append_array_invalid_value_length() { + let mut other_builder = FixedSizeBinaryBuilder::with_capacity(3, 4); + other_builder.append_value(b"test").unwrap(); + let other_array = other_builder.finish(); + let mut builder = FixedSizeBinaryBuilder::with_capacity(3, 5); + builder.append_array(&other_array).unwrap(); + } } From 87d5e5922e02d83b38a045322d171f8a43e7026e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E7=95=A5?= Date: Wed, 17 Dec 2025 21:06:51 +0800 Subject: [PATCH 2/2] refactor: recorrect test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 蔡略 --- arrow-array/src/builder/fixed_size_binary_builder.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arrow-array/src/builder/fixed_size_binary_builder.rs b/arrow-array/src/builder/fixed_size_binary_builder.rs index 9bcbfab04fa1..f6b4c33d9454 100644 --- a/arrow-array/src/builder/fixed_size_binary_builder.rs +++ b/arrow-array/src/builder/fixed_size_binary_builder.rs @@ -297,7 +297,7 @@ mod tests { other_builder.append_value(b"arrow").unwrap(); let other_array = other_builder.finish(); - let mut builder = FixedSizeBinaryBuilder::with_capacity(3, 5); + let mut builder = FixedSizeBinaryBuilder::with_capacity(6, 5); builder.append_array(&other_array).unwrap(); // Append again to test if breaks when appending multiple times builder.append_array(&other_array).unwrap(); @@ -312,10 +312,12 @@ mod tests { } assert_eq!(b"hello", array.value(0)); - assert_eq!(b"hello", array.value(3)); - assert_eq!(b"arrow", array.value(5)); assert!(array.is_null(1)); + assert_eq!(b"arrow", array.value(2)); + + assert_eq!(b"hello", array.value(3)); assert!(array.is_null(4)); + assert_eq!(b"arrow", array.value(5)); } #[test]