From 0457a0d6864cfa42f692a3cb227d9926c66632a0 Mon Sep 17 00:00:00 2001 From: Chojan Shang Date: Thu, 5 Aug 2021 10:31:52 +0800 Subject: [PATCH] Change to comfy-table Signed-off-by: Chojan Shang --- Cargo.toml | 4 ++-- src/io/print.rs | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ab5d26108f..93a56ea6a90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ serde_json = { version = "^1.0", features = ["preserve_order"], optional = true indexmap = { version = "^1.6", optional = true } # used to print columns in a nice columnar format -prettytable-rs = { version = "^0.8", optional = true } +comfy-table = { version = "4.0", optional = true } flatbuffers = { version = "=2.0.0", optional = true } hex = { version = "^0.4", optional = true } @@ -96,7 +96,7 @@ io_parquet_compression = [ "parquet2/brotli", ] io_json_integration = ["io_json", "hex"] -io_print = ["prettytable-rs"] +io_print = ["comfy-table"] # the compute kernels. Disabling this significantly reduces compile time. compute = [] # base64 + io_ipc because arrow schemas are stored as base64-encoded ipc format. diff --git a/src/io/print.rs b/src/io/print.rs index cc4b9ac26ae..102ab355956 100644 --- a/src/io/print.rs +++ b/src/io/print.rs @@ -17,8 +17,7 @@ use crate::{array::*, error::Result, record_batch::RecordBatch}; -use prettytable::format; -use prettytable::{Cell, Row, Table}; +use comfy_table::{Cell, Table}; /// Returns a visual representation of multiple [`RecordBatch`]es. pub fn write(batches: &[RecordBatch]) -> Result { @@ -27,14 +26,14 @@ pub fn write(batches: &[RecordBatch]) -> Result { /// Prints a visual representation of record batches to stdout pub fn print(results: &[RecordBatch]) -> Result<()> { - create_table(results)?.printstd(); + println!("{}", create_table(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); @@ -46,7 +45,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 { let displayes = batch @@ -61,7 +60,7 @@ fn create_table(results: &[RecordBatch]) -> Result
{ let string = displayes[col](row); cells.push(Cell::new(&string)); }); - table.add_row(Row::new(cells)); + table.add_row(cells); } }