This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 6762d0b69d Add support for building FixedSizeListBuilder in 
struct_builder's mak… (#6595)
6762d0b69d is described below

commit 6762d0b69daa65b70940491f0b56000af8fb1d6c
Author: Kevin Lim <[email protected]>
AuthorDate: Mon Oct 21 10:45:54 2024 -0700

    Add support for building FixedSizeListBuilder in struct_builder's mak… 
(#6595)
    
    * Add support for building FixedSizeListBuilder in struct_builder's 
make_builders
    
    * Fix formatting
    
    * Make suggested fixes + add test
---
 arrow-array/src/builder/struct_builder.rs | 34 +++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/arrow-array/src/builder/struct_builder.rs 
b/arrow-array/src/builder/struct_builder.rs
index c0e49b939f..4561e05258 100644
--- a/arrow-array/src/builder/struct_builder.rs
+++ b/arrow-array/src/builder/struct_builder.rs
@@ -253,6 +253,18 @@ pub fn make_builder(datatype: &DataType, capacity: usize) 
-> Box<dyn ArrayBuilde
             let builder = make_builder(field.data_type(), capacity);
             Box::new(LargeListBuilder::with_capacity(builder, 
capacity).with_field(field.clone()))
         }
+        DataType::FixedSizeList(field, size) => {
+            let size = *size;
+            let values_builder_capacity = {
+                let size: usize = size.try_into().unwrap();
+                capacity * size
+            };
+            let builder = make_builder(field.data_type(), 
values_builder_capacity);
+            Box::new(
+                FixedSizeListBuilder::with_capacity(builder, size, capacity)
+                    .with_field(field.clone()),
+            )
+        }
         DataType::Map(field, _) => match field.data_type() {
             DataType::Struct(fields) => {
                 let map_field_names = MapFieldNames {
@@ -520,6 +532,28 @@ mod tests {
         assert_eq!(0, builder.len());
     }
 
+    #[test]
+    fn test_build_fixed_size_list() {
+        const LIST_LENGTH: i32 = 4;
+        let fixed_size_list_dtype =
+            DataType::new_fixed_size_list(DataType::Int32, LIST_LENGTH, false);
+        let mut builder = make_builder(&fixed_size_list_dtype, 10);
+        let builder = builder
+            .as_any_mut()
+            .downcast_mut::<FixedSizeListBuilder<Box<dyn ArrayBuilder>>>();
+        match builder {
+            Some(builder) => {
+                assert_eq!(builder.value_length(), LIST_LENGTH);
+                assert!(builder
+                    .values()
+                    .as_any_mut()
+                    .downcast_mut::<Int32Builder>()
+                    .is_some());
+            }
+            None => panic!("expected FixedSizeListBuilder, got a different 
builder type"),
+        }
+    }
+
     #[test]
     fn test_struct_array_builder_finish_cloned() {
         let int_builder = Int32Builder::new();

Reply via email to