2020
2121use crate :: { array:: ArrayRef , record_batch:: RecordBatch } ;
2222
23- use prettytable:: format;
24- use prettytable:: { Cell , Row , Table } ;
23+ use comfy_table:: { Cell , Table } ;
2524
2625use crate :: error:: Result ;
2726
@@ -39,20 +38,20 @@ pub fn pretty_format_columns(col_name: &str, results: &[ArrayRef]) -> Result<Str
3938
4039///! Prints a visual representation of record batches to stdout
4140pub fn print_batches ( results : & [ RecordBatch ] ) -> Result < ( ) > {
42- create_table ( results) ?. printstd ( ) ;
41+ println ! ( "{}" , create_table( results) ?) ;
4342 Ok ( ( ) )
4443}
4544
4645///! Prints a visual representation of a list of column to stdout
4746pub fn print_columns ( col_name : & str , results : & [ ArrayRef ] ) -> Result < ( ) > {
48- create_column ( col_name, results) ?. printstd ( ) ;
47+ println ! ( "{}" , create_column( col_name, results) ?) ;
4948 Ok ( ( ) )
5049}
5150
5251///! Convert a series of record batches into a table
5352fn create_table ( results : & [ RecordBatch ] ) -> Result < Table > {
5453 let mut table = Table :: new ( ) ;
55- table. set_format ( * format :: consts :: FORMAT_NO_LINESEP_WITH_TITLE ) ;
54+ table. load_preset ( "||--+-++| ++++++" ) ;
5655
5756 if results. is_empty ( ) {
5857 return Ok ( table) ;
@@ -64,7 +63,7 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {
6463 for field in schema. fields ( ) {
6564 header. push ( Cell :: new ( & field. name ( ) ) ) ;
6665 }
67- table. set_titles ( Row :: new ( header) ) ;
66+ table. set_header ( header) ;
6867
6968 for batch in results {
7069 for row in 0 ..batch. num_rows ( ) {
@@ -73,7 +72,7 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {
7372 let column = batch. column ( col) ;
7473 cells. push ( Cell :: new ( & array_value_to_string ( & column, row) ?) ) ;
7574 }
76- table. add_row ( Row :: new ( cells) ) ;
75+ table. add_row ( cells) ;
7776 }
7877 }
7978
@@ -82,19 +81,19 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {
8281
8382fn create_column ( field : & str , columns : & [ ArrayRef ] ) -> Result < Table > {
8483 let mut table = Table :: new ( ) ;
85- table. set_format ( * format :: consts :: FORMAT_NO_LINESEP_WITH_TITLE ) ;
84+ table. load_preset ( "||--+-++| ++++++" ) ;
8685
8786 if columns. is_empty ( ) {
8887 return Ok ( table) ;
8988 }
9089
9190 let header = vec ! [ Cell :: new( field) ] ;
92- table. set_titles ( Row :: new ( header) ) ;
91+ table. set_header ( header) ;
9392
9493 for col in columns {
9594 for row in 0 ..col. len ( ) {
9695 let cells = vec ! [ Cell :: new( & array_value_to_string( & col, row) ?) ] ;
97- table. add_row ( Row :: new ( cells) ) ;
96+ table. add_row ( cells) ;
9897 }
9998 }
10099
0 commit comments