@@ -20,7 +20,7 @@ impl Display for Scalar {
2020 DType :: Binary ( _) => write ! ( f, "{}" , self . as_binary( ) ) ,
2121 DType :: List ( ..) | DType :: FixedSizeList ( ..) => write ! ( f, "{}" , self . as_list( ) ) ,
2222 DType :: Struct ( ..) => write ! ( f, "{}" , self . as_struct( ) ) ,
23- DType :: Union ( ..) => todo ! ( "TODO(connor)[Union]: unimplemented" ) ,
23+ DType :: Union ( ..) => write ! ( f , "{}" , self . as_union ( ) ) ,
2424 DType :: Variant ( _) => write ! ( f, "{}" , self . as_variant( ) ) ,
2525 DType :: Extension ( _) => write ! ( f, "{}" , self . as_extension( ) ) ,
2626 }
@@ -30,13 +30,15 @@ impl Display for Scalar {
3030#[ cfg( test) ]
3131mod tests {
3232 use vortex_buffer:: ByteBuffer ;
33+ use vortex_error:: VortexResult ;
3334
3435 use crate :: dtype:: DType ;
3536 use crate :: dtype:: FieldName ;
3637 use crate :: dtype:: Nullability :: NonNullable ;
3738 use crate :: dtype:: Nullability :: Nullable ;
3839 use crate :: dtype:: PType ;
3940 use crate :: dtype:: StructFields ;
41+ use crate :: dtype:: UnionVariants ;
4042 use crate :: extension:: datetime:: Date ;
4143 use crate :: extension:: datetime:: Time ;
4244 use crate :: extension:: datetime:: TimeUnit ;
@@ -79,6 +81,30 @@ mod tests {
7981 ) ;
8082 }
8183
84+ #[ test]
85+ fn display_union ( ) -> VortexResult < ( ) > {
86+ let variants = UnionVariants :: new (
87+ [ "int" , "string" ] . into ( ) ,
88+ vec ! [
89+ DType :: Primitive ( PType :: I32 , Nullable ) ,
90+ DType :: Utf8 ( NonNullable ) ,
91+ ] ,
92+ ) ?;
93+
94+ let scalar = Scalar :: union ( variants. clone ( ) , 0 , Scalar :: primitive ( 42_i32 , Nullable ) ) ?;
95+
96+ assert_eq ! ( format!( "{scalar}" ) , "int(42i32)" ) ;
97+ let inner_null = Scalar :: union (
98+ variants. clone ( ) ,
99+ 0 ,
100+ Scalar :: null ( DType :: Primitive ( PType :: I32 , Nullable ) ) ,
101+ ) ?;
102+ assert_eq ! ( format!( "{inner_null}" ) , "int(null)" ) ;
103+ assert_eq ! ( format!( "{}" , Scalar :: null( DType :: Union ( variants) ) ) , "null" ) ;
104+
105+ Ok ( ( ) )
106+ }
107+
82108 #[ test]
83109 fn display_utf8 ( ) {
84110 assert_eq ! (
0 commit comments