@@ -104,7 +104,7 @@ impl DType {
104104 } )
105105 . collect :: < VortexResult < Vec < _ > > > ( ) ?;
106106 let variants = UnionVariants :: try_new ( names, dtypes, type_ids) ?;
107- Ok ( Self :: Union ( variants) )
107+ Ok ( Self :: Union ( variants, u . nullable . into ( ) ) )
108108 }
109109 DtypeType :: Variant ( v) => Ok ( Self :: Variant ( v. nullable . into ( ) ) ) ,
110110 DtypeType :: Extension ( e) => {
@@ -173,13 +173,14 @@ impl TryFrom<&DType> for pb::DType {
173173 . collect :: < VortexResult < Vec < _ > > > ( ) ?,
174174 nullable : ( * null) . into ( ) ,
175175 } ) ,
176- DType :: Union ( uv) => DtypeType :: Union ( pb:: Union {
176+ DType :: Union ( uv, null ) => DtypeType :: Union ( pb:: Union {
177177 names : uv. names ( ) . iter ( ) . map ( |n| n. as_ref ( ) . to_string ( ) ) . collect ( ) ,
178178 dtypes : uv
179179 . variants ( )
180180 . map ( |d| Self :: try_from ( & d) )
181181 . collect :: < VortexResult < Vec < _ > > > ( ) ?,
182182 type_ids : uv. type_ids ( ) . iter ( ) . map ( |t| * t as i32 ) . collect ( ) ,
183+ nullable : ( * null) . into ( ) ,
183184 } ) ,
184185 DType :: Variant ( null) => DtypeType :: Variant ( pb:: Variant {
185186 nullable : ( * null) . into ( ) ,
@@ -416,22 +417,20 @@ mod tests {
416417 ] ,
417418 )
418419 . unwrap ( ) ;
419- let dtype = DType :: Union ( variants) ;
420+ let dtype = DType :: Union ( variants, Nullability :: NonNullable ) ;
420421 let converted = round_trip_dtype ( & dtype) ;
421422 assert_eq ! ( dtype, converted) ;
422423 }
423424
424425 #[ test]
425- fn test_union_round_trip_proto_with_nullable_variant ( ) {
426+ fn test_union_round_trip_proto_with_inner_and_outer_nullability ( ) {
426427 let variants = UnionVariants :: new (
427428 [ "null_variant" , "str" ] . into ( ) ,
428429 vec ! [ DType :: Null , DType :: Utf8 ( Nullability :: NonNullable ) ] ,
429430 )
430431 . unwrap ( ) ;
431432
432- assert_eq ! ( variants. derived_nullability( ) , Nullability :: Nullable ) ;
433-
434- let dtype = DType :: Union ( variants) ;
433+ let dtype = DType :: Union ( variants, Nullability :: Nullable ) ;
435434 let converted = round_trip_dtype ( & dtype) ;
436435 assert_eq ! ( dtype, converted) ;
437436 }
@@ -449,11 +448,11 @@ mod tests {
449448 )
450449 . unwrap ( ) ;
451450
452- let dtype = DType :: Union ( variants) ;
451+ let dtype = DType :: Union ( variants, Nullability :: Nullable ) ;
453452 let converted = round_trip_dtype ( & dtype) ;
454453 assert_eq ! ( dtype, converted) ;
455454
456- let DType :: Union ( uv) = & converted else {
455+ let DType :: Union ( uv, _ ) = & converted else {
457456 panic ! ( "Expected Union" ) ;
458457 } ;
459458 assert_eq ! ( uv. type_ids( ) , & [ 0 , 5 , 7 ] ) ;
@@ -471,6 +470,7 @@ mod tests {
471470 ] ,
472471 // 256 does not fit in u8.
473472 type_ids : vec ! [ 256 ] ,
473+ nullable : false ,
474474 } ) ) ,
475475 } ;
476476
@@ -495,6 +495,7 @@ mod tests {
495495 ] ,
496496 )
497497 . unwrap ( ) ,
498+ Nullability :: NonNullable ,
498499 ) ;
499500
500501 let struct_with_union = DType :: Struct (
@@ -511,6 +512,7 @@ mod tests {
511512 vec ! [ DType :: Utf8 ( Nullability :: NonNullable ) , struct_with_union] ,
512513 )
513514 . unwrap ( ) ,
515+ Nullability :: Nullable ,
514516 ) ;
515517
516518 let converted = round_trip_dtype ( & outer_union) ;
0 commit comments