File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ pub mod util;
2+
3+ use arrow:: record_batch:: RecordBatch ;
4+ use arrow:: datatypes:: { DataType , Field , Schema , SchemaRef } ;
5+ use arrow:: error:: ArrowError ;
6+
7+ pub fn record_batch_to_string ( batch : & RecordBatch ) -> Result < String , ArrowError > {
8+ let mut output = String :: new ( ) ;
9+ for row in 0 ..batch. num_rows ( ) {
10+ for col in 0 ..batch. num_columns ( ) {
11+ if col != 0 {
12+ output. push ( ' ' ) ;
13+ }
14+ let column = batch. column ( col) ;
15+
16+ // NULL values are rendered as "NULL".
17+ if column. is_null ( row) {
18+ output. push_str ( "NULL" ) ;
19+ continue ;
20+ }
21+ let string = array_value_to_string ( column, row) ?;
22+
23+ // Empty strings are rendered as "(empty)".
24+ if * column. data_type ( ) == DataType :: Utf8 && string. is_empty ( ) {
25+ output. push_str ( "(empty)" ) ;
26+ continue ;
27+ }
28+ output. push_str ( & string) ;
29+ }
30+ output. push ( '\n' ) ;
31+ }
32+
33+ Ok ( output)
34+ }
You can’t perform that action at this time.
0 commit comments