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

[CLI] Emit correct row count from CLI sql subcommand JSON mode #1685

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all 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
9 changes: 8 additions & 1 deletion cli/src/commands/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ async fn run_query(env: &CliEnv, sql_opts: &Sql) -> Result<()> {
}
table.set_styled_header(headers);

let mut row_count: usize = 0;
if sql_opts.json {
let mut writer = arrow::json::ArrayWriter::new(io::stdout());
for batch in resp.batches {
row_count += batch.num_rows();
writer.write_batches(&[&batch])?;
}
writer.finish()?;
} else if sql_opts.jsonl {
let mut writer = arrow::json::LineDelimitedWriter::new(io::stdout());
for batch in resp.batches {
row_count += batch.num_rows();
writer.write_batches(&[&batch])?;
}
writer.finish()?;
Expand Down Expand Up @@ -110,7 +113,11 @@ async fn run_query(env: &CliEnv, sql_opts: &Sql) -> Result<()> {

c_eprintln!(
"{} rows. Query took {:?}",
table.row_count(),
if sql_opts.json || sql_opts.jsonl {
row_count
} else {
table.row_count()
},
Styled(Style::Notice, start_time.elapsed())
);
Ok(())
Expand Down
Loading