Skip to content

Commit

Permalink
Change to comfy-table from prettytable-rs (apache#656)
Browse files Browse the repository at this point in the history
* Change to comfy-table

Signed-off-by: Chojan Shang <psiace@outlook.com>

* Apply review

Signed-off-by: Chojan Shang <psiace@outlook.com>
  • Loading branch information
Chojan Shang authored and ovr committed Apr 16, 2024
1 parent 4b05fac commit ba5455c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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"
Expand All @@ -63,7 +63,7 @@ avx512 = []
csv = ["csv_crate"]
ipc = ["flatbuffers"]
simd = ["packed_simd"]
prettyprint = ["prettytable-rs"]
prettyprint = ["comfy-table"]
js = ["getrandom/js"]
# The test utils feature enables code used in benchmarks and tests but
# not the core arrow code itself
Expand Down
19 changes: 9 additions & 10 deletions arrow/src/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,20 +38,20 @@ pub fn pretty_format_columns(col_name: &str, results: &[ArrayRef]) -> Result<Str

///! Prints a visual representation of record batches to stdout
pub fn print_batches(results: &[RecordBatch]) -> 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<Table> {
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);
Expand All @@ -64,7 +63,7 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {
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() {
Expand All @@ -73,7 +72,7 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {
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);
}
}

Expand All @@ -82,19 +81,19 @@ fn create_table(results: &[RecordBatch]) -> Result<Table> {

fn create_column(field: &str, columns: &[ArrayRef]) -> Result<Table> {
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);
}
}

Expand Down

0 comments on commit ba5455c

Please sign in to comment.