@@ -632,6 +632,61 @@ fn array_from_json(
632632 let array = MapArray :: from ( array_data) ;
633633 Ok ( Arc :: new ( array) )
634634 }
635+ DataType :: Union ( fields, _) => {
636+ let field_type_ids = fields
637+ . iter ( )
638+ . enumerate ( )
639+ . into_iter ( )
640+ . map ( |( idx, f) | {
641+ (
642+ f. metadata ( )
643+ . and_then ( |m| m. get ( "type_id" ) )
644+ . unwrap ( )
645+ . parse :: < i8 > ( )
646+ . unwrap ( ) ,
647+ idx,
648+ )
649+ } )
650+ . collect :: < HashMap < _ , _ > > ( ) ;
651+
652+ let type_ids = if let Some ( type_id) = json_col. type_id {
653+ type_id
654+ . iter ( )
655+ . map ( |t| {
656+ if field_type_ids. contains_key ( t) {
657+ Ok ( * ( field_type_ids. get ( t) . unwrap ( ) ) as i8 )
658+ } else {
659+ Err ( ArrowError :: JsonError ( format ! (
660+ "Unable to find type id {:?}" ,
661+ t
662+ ) ) )
663+ }
664+ } )
665+ . collect :: < Result < _ > > ( ) ?
666+ } else {
667+ vec ! [ ]
668+ } ;
669+
670+ let offset: Option < Buffer > = json_col. offset . map ( |offsets| {
671+ let offsets: Vec < i32 > =
672+ offsets. iter ( ) . map ( |v| v. as_i64 ( ) . unwrap ( ) as i32 ) . collect ( ) ;
673+ Buffer :: from ( & offsets. to_byte_slice ( ) )
674+ } ) ;
675+
676+ let mut children: Vec < ( Field , Arc < dyn Array > ) > = vec ! [ ] ;
677+ for ( field, col) in fields. iter ( ) . zip ( json_col. children . unwrap ( ) ) {
678+ let array = array_from_json ( field, col, dictionaries) ?;
679+ children. push ( ( field. clone ( ) , array) ) ;
680+ }
681+
682+ let array = UnionArray :: try_new (
683+ Buffer :: from ( & type_ids. to_byte_slice ( ) ) ,
684+ offset,
685+ children,
686+ )
687+ . unwrap ( ) ;
688+ Ok ( Arc :: new ( array) )
689+ }
635690 t => Err ( ArrowError :: JsonError ( format ! (
636691 "data type {:?} not supported" ,
637692 t
0 commit comments