20
20
21
21
use crate :: { array:: ArrayRef , record_batch:: RecordBatch } ;
22
22
23
- use prettytable:: format;
24
- use prettytable:: { Cell , Row , Table } ;
23
+ use comfy_table:: { Cell , Table } ;
25
24
26
25
use crate :: error:: Result ;
27
26
@@ -39,20 +38,20 @@ pub fn pretty_format_columns(col_name: &str, results: &[ArrayRef]) -> Result<Str
39
38
40
39
///! Prints a visual representation of record batches to stdout
41
40
pub fn print_batches ( results : & [ RecordBatch ] ) -> Result < ( ) > {
42
- create_table ( results) ?. printstd ( ) ;
41
+ println ! ( "{}" , create_table( results) ?) ;
43
42
Ok ( ( ) )
44
43
}
45
44
46
45
///! Prints a visual representation of a list of column to stdout
47
46
pub fn print_columns ( col_name : & str , results : & [ ArrayRef ] ) -> Result < ( ) > {
48
- create_column ( col_name, results) ?. printstd ( ) ;
47
+ println ! ( "{}" , create_column( col_name, results) ?) ;
49
48
Ok ( ( ) )
50
49
}
51
50
52
51
///! Convert a series of record batches into a table
53
52
fn create_table ( results : & [ RecordBatch ] ) -> Result < Table > {
54
53
let mut table = Table :: new ( ) ;
55
- table. set_format ( * format :: consts :: FORMAT_NO_LINESEP_WITH_TITLE ) ;
54
+ table. load_preset ( "||--+-++| ++++++" ) ;
56
55
57
56
if results. is_empty ( ) {
58
57
return Ok ( table) ;
@@ -64,7 +63,7 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {
64
63
for field in schema. fields ( ) {
65
64
header. push ( Cell :: new ( & field. name ( ) ) ) ;
66
65
}
67
- table. set_titles ( Row :: new ( header) ) ;
66
+ table. set_header ( header) ;
68
67
69
68
for batch in results {
70
69
for row in 0 ..batch. num_rows ( ) {
@@ -73,7 +72,7 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {
73
72
let column = batch. column ( col) ;
74
73
cells. push ( Cell :: new ( & array_value_to_string ( & column, row) ?) ) ;
75
74
}
76
- table. add_row ( Row :: new ( cells) ) ;
75
+ table. add_row ( cells) ;
77
76
}
78
77
}
79
78
@@ -82,19 +81,19 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {
82
81
83
82
fn create_column ( field : & str , columns : & [ ArrayRef ] ) -> Result < Table > {
84
83
let mut table = Table :: new ( ) ;
85
- table. set_format ( * format :: consts :: FORMAT_NO_LINESEP_WITH_TITLE ) ;
84
+ table. load_preset ( "||--+-++| ++++++" ) ;
86
85
87
86
if columns. is_empty ( ) {
88
87
return Ok ( table) ;
89
88
}
90
89
91
90
let header = vec ! [ Cell :: new( field) ] ;
92
- table. set_titles ( Row :: new ( header) ) ;
91
+ table. set_header ( header) ;
93
92
94
93
for col in columns {
95
94
for row in 0 ..col. len ( ) {
96
95
let cells = vec ! [ Cell :: new( & array_value_to_string( & col, row) ?) ] ;
97
- table. add_row ( Row :: new ( cells) ) ;
96
+ table. add_row ( cells) ;
98
97
}
99
98
}
100
99
0 commit comments