istvan-fodor commented on issue #5494:
URL: https://github.com/apache/arrow-rs/issues/5494#issuecomment-1987449478

   @tustvold @alamb I was able to get this to work with the following code. 
Took the Box<any ArrayBuilder> and downcasted it.
   
   ```rust
   use arrow::{
       array::{ArrayBuilder, StructBuilder},
       datatypes::{DataType, Field, Fields},
   };
   use std::sync::Arc;
   
   fn main() {
       let mut status = arrow::array::builder::ListBuilder::new(
           arrow::array::StructBuilder::from_fields(status_schema(), 0),
       );
   
       let mut struct_builder: &mut arrow::array::StructBuilder = 
status.values();
   
       let mut list_builder_option = struct_builder
           .field_builder::<arrow::array::builder::ListBuilder<Box<dyn 
arrow::array::ArrayBuilder>>>(
               1usize,
           );
       let mut struct_builder = list_builder_option.as_mut().unwrap();
       let mut struct_builder: &mut arrow::array::StructBuilder = struct_builder
           .values()
           .as_any_mut()
           .downcast_mut::<StructBuilder>()
           .unwrap();
   }
   
   pub fn status_schema() -> Vec<Field> {
       vec![
           Field::new("id", DataType::Utf8, true),
           Field::new(
               "values",
               DataType::List(Arc::new(Field::new(
                   "item",
                   DataType::Struct(Fields::from(key_value_schema())),
                   true,
               ))),
               true,
           ),
       ]
   }
   pub fn key_value_schema() -> Vec<Field> {
       vec![
           Field::new("key", DataType::Utf8, true),
           Field::new("value", DataType::Utf8, true),
       ]
   }
   
   ```
   
   


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