1717
1818use std:: { collections:: HashMap , fmt} ;
1919
20- use crate :: DataType ;
20+ use crate :: { DataType , field } ;
2121
2222impl fmt:: Display for DataType {
2323 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -125,7 +125,7 @@ impl fmt::Display for DataType {
125125 format ! ( "{name:?}: {maybe_nullable}{data_type}{metadata_str}" )
126126 } )
127127 . collect :: < Vec < _ > > ( )
128- . join ( ", " ) ;
128+ . join ( "; " ) ;
129129 write ! ( f, "{fields_str}" ) ?;
130130 }
131131 write ! ( f, ")" ) ?;
@@ -145,7 +145,7 @@ impl fmt::Display for DataType {
145145 format ! ( "{type_id:?}: {maybe_nullable}{data_type}{metadata_str}" )
146146 } )
147147 . collect :: < Vec < _ > > ( )
148- . join ( ", " ) ;
148+ . join ( "; " ) ;
149149 write ! ( f, "{fields_str}" ) ?;
150150 }
151151 write ! ( f, ")" ) ?;
@@ -266,6 +266,33 @@ mod tests {
266266 assert_eq ! ( fixed_size_metadata_string, expected_metadata_string) ;
267267 }
268268
269+ #[ test]
270+ fn test_display_struct ( ) {
271+ let fields = vec ! [
272+ Field :: new( "a" , DataType :: Int32 , false ) ,
273+ Field :: new( "b" , DataType :: Utf8 , true ) ,
274+ ] ;
275+ let struct_data_type = DataType :: Struct ( fields. into ( ) ) ;
276+ let struct_data_type_string = struct_data_type. to_string ( ) ;
277+ let expected_string = "Struct(\" a\" : Int32; \" b\" : nullable Utf8)" ;
278+ assert_eq ! ( struct_data_type_string, expected_string) ;
279+
280+ // Test with metadata
281+ let mut field_with_metadata = Field :: new ( "b" , DataType :: Utf8 , true ) ;
282+ let metadata = HashMap :: from ( [ ( "key" . to_string ( ) , "value" . to_string ( ) ) ] ) ;
283+ field_with_metadata. set_metadata ( metadata) ;
284+ let struct_fields_with_metadata =
285+ vec ! [ Field :: new( "a" , DataType :: Int32 , false ) , field_with_metadata] ;
286+ let struct_data_type_with_metadata = DataType :: Struct ( struct_fields_with_metadata. into ( ) ) ;
287+ let struct_data_type_with_metadata_string = struct_data_type_with_metadata. to_string ( ) ;
288+ let expected_string_with_metadata =
289+ "Struct(\" a\" : Int32; \" b\" : nullable Utf8, metadata: {\" key\" : \" value\" })" ;
290+ assert_eq ! (
291+ struct_data_type_with_metadata_string,
292+ expected_string_with_metadata
293+ ) ;
294+ }
295+
269296 #[ test]
270297 fn test_display_union ( ) {
271298 let fields = vec ! [
@@ -280,7 +307,7 @@ mod tests {
280307
281308 let union_data_type = DataType :: Union ( union_fields, crate :: UnionMode :: Sparse ) ;
282309 let union_data_type_string = union_data_type. to_string ( ) ;
283- let expected_string = "Union(Sparse, 0: Int32, 1: nullable Utf8)" ;
310+ let expected_string = "Union(Sparse, 0: Int32; 1: nullable Utf8)" ;
284311 assert_eq ! ( union_data_type_string, expected_string) ;
285312
286313 // Test with metadata
@@ -297,7 +324,7 @@ mod tests {
297324 DataType :: Union ( union_fields_with_metadata, crate :: UnionMode :: Sparse ) ;
298325 let union_data_type_with_metadata_string = union_data_type_with_metadata. to_string ( ) ;
299326 let expected_string_with_metadata =
300- "Union(Sparse, 0: Int32, 1: nullable Utf8, metadata: {\" key\" : \" value\" })" ;
327+ "Union(Sparse, 0: Int32; 1: nullable Utf8, metadata: {\" key\" : \" value\" })" ;
301328 assert_eq ! (
302329 union_data_type_with_metadata_string,
303330 expected_string_with_metadata
0 commit comments