@@ -304,13 +304,16 @@ impl TryFrom<&protobuf::arrow_type::ArrowTypeEnum> for DataType {
304304 } ;
305305 let union_fields = parse_proto_fields_to_fields ( & union. union_types ) ?;
306306
307- // Default to index based type ids if not provided
308- let type_ids: Vec < _ > = match union. type_ids . is_empty ( ) {
309- true => ( 0 ..union_fields. len ( ) as i8 ) . collect ( ) ,
310- false => union. type_ids . iter ( ) . map ( |i| * i as i8 ) . collect ( ) ,
307+ // Default to index based type ids if not explicitly provided
308+ let union_fields = if union. type_ids . is_empty ( ) {
309+ UnionFields :: from_fields ( union_fields)
310+ } else {
311+ let type_ids = union. type_ids . iter ( ) . map ( |i| * i as i8 ) ;
312+ UnionFields :: try_new ( type_ids, union_fields) . map_err ( |e| {
313+ DataFusionError :: from ( e) . context ( "Deserializing Union DataType" )
314+ } ) ?
311315 } ;
312-
313- DataType :: Union ( UnionFields :: new ( type_ids, union_fields) , union_mode)
316+ DataType :: Union ( union_fields, union_mode)
314317 }
315318 arrow_type:: ArrowTypeEnum :: Dictionary ( dict) => {
316319 let key_datatype = dict. as_ref ( ) . key . as_deref ( ) . required ( "key" ) ?;
@@ -602,7 +605,9 @@ impl TryFrom<&protobuf::ScalarValue> for ScalarValue {
602605 . collect :: < Option < Vec < _ > > > ( ) ;
603606 let fields = fields. ok_or_else ( || Error :: required ( "UnionField" ) ) ?;
604607 let fields = parse_proto_fields_to_fields ( & fields) ?;
605- let fields = UnionFields :: new ( ids, fields) ;
608+ let union_fields = UnionFields :: try_new ( ids, fields) . map_err ( |e| {
609+ DataFusionError :: from ( e) . context ( "Deserializing Union ScalarValue" )
610+ } ) ?;
606611 let v_id = val. value_id as i8 ;
607612 let val = match & val. value {
608613 None => None ,
@@ -614,7 +619,7 @@ impl TryFrom<&protobuf::ScalarValue> for ScalarValue {
614619 Some ( ( v_id, Box :: new ( val) ) )
615620 }
616621 } ;
617- Self :: Union ( val, fields , mode)
622+ Self :: Union ( val, union_fields , mode)
618623 }
619624 Value :: FixedSizeBinaryValue ( v) => {
620625 Self :: FixedSizeBinary ( v. length , Some ( v. clone ( ) . values ) )
0 commit comments