diff --git a/arrow/Cargo.toml b/arrow/Cargo.toml index 0c8ca76b7890..cadd4ff16190 100644 --- a/arrow/Cargo.toml +++ b/arrow/Cargo.toml @@ -49,7 +49,7 @@ packed_simd = { version = "0.3", optional = true, package = "packed_simd_2" } chrono = "0.4" flatbuffers = { version = "=2.0.0", optional = true } hex = "0.4" -prettytable-rs = { version = "0.8.0", optional = true } +comfy-table = { version = "4.0", optional = true, default-features = false } lexical-core = "^0.7" multiversion = "0.6.1" bitflags = "1.2.1" @@ -60,7 +60,7 @@ avx512 = [] csv = ["csv_crate"] ipc = ["flatbuffers"] simd = ["packed_simd"] -prettyprint = ["prettytable-rs"] +prettyprint = ["comfy-table"] # The test utils feature enables code used in benchmarks and tests but # not the core arrow code itself. Be aware that `rand` must be kept as # an optional dependency for supporting compile to wasm32-unknown-unknown diff --git a/arrow/src/util/pretty.rs b/arrow/src/util/pretty.rs index f9599448c799..28bb0165ddd9 100644 --- a/arrow/src/util/pretty.rs +++ b/arrow/src/util/pretty.rs @@ -20,8 +20,7 @@ use crate::{array::ArrayRef, record_batch::RecordBatch}; -use prettytable::format; -use prettytable::{Cell, Row, Table}; +use comfy_table::{Cell, Table}; use crate::error::Result; @@ -39,20 +38,20 @@ pub fn pretty_format_columns(col_name: &str, results: &[ArrayRef]) -> Result Result<()> { - create_table(results)?.printstd(); + println!("{}", create_table(results)?); Ok(()) } ///! Prints a visual representation of a list of column to stdout pub fn print_columns(col_name: &str, results: &[ArrayRef]) -> Result<()> { - create_column(col_name, results)?.printstd(); + println!("{}", create_column(col_name, results)?); Ok(()) } ///! Convert a series of record batches into a table fn create_table(results: &[RecordBatch]) -> Result { let mut table = Table::new(); - table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); + table.load_preset("||--+-++| ++++++"); if results.is_empty() { return Ok(table); @@ -64,7 +63,7 @@ fn create_table(results: &[RecordBatch]) -> Result
{ for field in schema.fields() { header.push(Cell::new(&field.name())); } - table.set_titles(Row::new(header)); + table.set_header(header); for batch in results { for row in 0..batch.num_rows() { @@ -73,7 +72,7 @@ fn create_table(results: &[RecordBatch]) -> Result
{ let column = batch.column(col); cells.push(Cell::new(&array_value_to_string(&column, row)?)); } - table.add_row(Row::new(cells)); + table.add_row(cells); } } @@ -82,19 +81,19 @@ fn create_table(results: &[RecordBatch]) -> Result
{ fn create_column(field: &str, columns: &[ArrayRef]) -> Result
{ let mut table = Table::new(); - table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); + table.load_preset("||--+-++| ++++++"); if columns.is_empty() { return Ok(table); } let header = vec![Cell::new(field)]; - table.set_titles(Row::new(header)); + table.set_header(header); for col in columns { for row in 0..col.len() { let cells = vec![Cell::new(&array_value_to_string(&col, row)?)]; - table.add_row(Row::new(cells)); + table.add_row(cells); } }