@@ -595,7 +595,7 @@ fn type_union_resolution_coercion(
595
595
596
596
/// Handle type union resolution including struct type and others.
597
597
pub fn try_type_union_resolution ( data_types : & [ DataType ] ) -> Result < Vec < DataType > > {
598
- let err = match try_type_union_resolution_with_struct ( data_types) {
598
+ let err = match try_type_union_resolution_with_struct ( data_types, false ) {
599
599
Ok ( struct_types) => return Ok ( struct_types) ,
600
600
Err ( e) => Some ( e) ,
601
601
} ;
@@ -611,6 +611,7 @@ pub fn try_type_union_resolution(data_types: &[DataType]) -> Result<Vec<DataType
611
611
// Since field name is the key of the struct, so it shouldn't be updated to the common column name like "c0" or "c1"
612
612
pub fn try_type_union_resolution_with_struct (
613
613
data_types : & [ DataType ] ,
614
+ is_unique : bool ,
614
615
) -> Result < Vec < DataType > > {
615
616
let mut keys_string: Option < String > = None ;
616
617
for data_type in data_types {
@@ -632,6 +633,12 @@ pub fn try_type_union_resolution_with_struct(
632
633
}
633
634
}
634
635
636
+ let first_fields = if let DataType :: Struct ( fields) = & data_types[ 0 ] {
637
+ fields. clone ( )
638
+ } else {
639
+ return internal_err ! ( "Struct type is checked is the previous function, so this should be unreachable" ) ;
640
+ } ;
641
+
635
642
let mut struct_types_map: HashMap < String , DataType > = if let DataType :: Struct (
636
643
fields,
637
644
) = & data_types[ 0 ]
@@ -650,7 +657,7 @@ pub fn try_type_union_resolution_with_struct(
650
657
let field_name = field. name ( ) ;
651
658
if let Some ( existing_type) = struct_types_map. get_mut ( field_name) {
652
659
if let Some ( coerced_type) =
653
- type_union_resolution_coercion ( & field. data_type ( ) , existing_type)
660
+ type_union_resolution_coercion ( field. data_type ( ) , existing_type)
654
661
{
655
662
* existing_type = coerced_type;
656
663
} else {
@@ -669,6 +676,20 @@ pub fn try_type_union_resolution_with_struct(
669
676
}
670
677
}
671
678
679
+ if is_unique {
680
+ let new_fields =
681
+ first_fields
682
+ . iter ( )
683
+ . map ( |f| {
684
+ Arc :: new ( Arc :: unwrap_or_clone ( Arc :: clone ( f) ) . with_data_type (
685
+ struct_types_map. get ( f. name ( ) ) . unwrap ( ) . to_owned ( ) ,
686
+ ) )
687
+ } )
688
+ . collect ( ) ;
689
+ let unified_struct = DataType :: Struct ( new_fields) ;
690
+ return Ok ( vec ! [ unified_struct; data_types. len( ) ] ) ;
691
+ }
692
+
672
693
let mut final_struct_types = vec ! [ ] ;
673
694
for s in data_types {
674
695
let mut new_fields = vec ! [ ] ;
0 commit comments