@@ -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,39 @@ 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 (
95+ variants. clone ( ) ,
96+ 0 ,
97+ Scalar :: primitive ( 42_i32 , Nullable ) ,
98+ Nullable ,
99+ ) ?;
100+
101+ assert_eq ! ( format!( "{scalar}" ) , "int(42i32)" ) ;
102+ let inner_null = Scalar :: union (
103+ variants. clone ( ) ,
104+ 0 ,
105+ Scalar :: null ( DType :: Primitive ( PType :: I32 , Nullable ) ) ,
106+ Nullable ,
107+ ) ?;
108+ assert_eq ! ( format!( "{inner_null}" ) , "int(null)" ) ;
109+ assert_eq ! (
110+ format!( "{}" , Scalar :: null( DType :: Union ( variants, Nullable ) ) ) ,
111+ "null"
112+ ) ;
113+
114+ Ok ( ( ) )
115+ }
116+
82117 #[ test]
83118 fn display_utf8 ( ) {
84119 assert_eq ! (
0 commit comments