File tree 1 file changed +11
-14
lines changed
1 file changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -71,24 +71,21 @@ impl fmt::Display for PrintFormat {
71
71
}
72
72
73
73
fn print_batches_to_json < J : JsonFormat > ( batches : & [ RecordBatch ] ) -> Result < String > {
74
+ use arrow:: io:: json:: write as json_write;
75
+
74
76
if batches. is_empty ( ) {
75
77
return Ok ( "{}" . to_string ( ) ) ;
76
78
}
77
79
let mut bytes = vec ! [ ] ;
78
- let schema = batches[ 0 ] . schema ( ) ;
79
- let names = schema
80
- . fields
81
- . iter ( )
82
- . map ( |f| f. name . clone ( ) )
83
- . collect :: < Vec < String > > ( ) ;
84
- for batch in batches {
85
- arrow:: io:: json:: write:: serialize (
86
- & names,
87
- batch. columns ( ) ,
88
- J :: default ( ) ,
89
- & mut bytes,
90
- ) ;
91
- }
80
+
81
+ let format = J :: default ( ) ;
82
+ let blocks = json_write:: Serializer :: new (
83
+ batches. into_iter ( ) . map ( |r| Ok ( r. clone ( ) ) ) ,
84
+ vec ! [ ] ,
85
+ format,
86
+ ) ;
87
+ json_write:: write ( & mut bytes, format, blocks) ?;
88
+
92
89
let formatted = String :: from_utf8 ( bytes)
93
90
. map_err ( |e| DataFusionError :: Execution ( e. to_string ( ) ) ) ?;
94
91
Ok ( formatted)
You can’t perform that action at this time.
0 commit comments