Skip to content

Commit ba5455c

Browse files
Chojan Shangovr
authored andcommitted
Change to comfy-table from prettytable-rs (apache#656)
* Change to comfy-table Signed-off-by: Chojan Shang <[email protected]> * Apply review Signed-off-by: Chojan Shang <[email protected]>
1 parent 4b05fac commit ba5455c

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

arrow/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ packed_simd = { version = "0.3", optional = true, package = "packed_simd_2" }
5252
chrono = "0.4"
5353
flatbuffers = { version = "=2.0.0", optional = true }
5454
hex = "0.4"
55-
prettytable-rs = { version = "0.8.0", optional = true }
55+
comfy-table = { version = "4.0", optional = true, default-features = false }
5656
lexical-core = "^0.7"
5757
multiversion = "0.6.1"
5858
bitflags = "1.2.1"
@@ -63,7 +63,7 @@ avx512 = []
6363
csv = ["csv_crate"]
6464
ipc = ["flatbuffers"]
6565
simd = ["packed_simd"]
66-
prettyprint = ["prettytable-rs"]
66+
prettyprint = ["comfy-table"]
6767
js = ["getrandom/js"]
6868
# The test utils feature enables code used in benchmarks and tests but
6969
# not the core arrow code itself

arrow/src/util/pretty.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
2121
use crate::{array::ArrayRef, record_batch::RecordBatch};
2222

23-
use prettytable::format;
24-
use prettytable::{Cell, Row, Table};
23+
use comfy_table::{Cell, Table};
2524

2625
use 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
4140
pub 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
4746
pub 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
5352
fn 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

8382
fn 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

Comments
 (0)