Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change to comfy-table from prettytable-rs #656

Merged
merged 3 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add default-features = false. This will allow the prettyprint feature to be enabled in wasm32-wasi target in the next comfy-table release.
Ref: Nukesor/comfy-table#47

FYI @jorgecarleitao

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

lexical-core = "^0.7"
multiversion = "0.6.1"
bitflags = "1.2.1"
Expand All @@ -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
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