feat: add row counts to SQL repl output (#1405)

* feat: add row counts to repl

* fix: fmt

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
pull/24376/head
Andrew Lamb 2021-05-04 06:57:16 -04:00 committed by GitHub
parent 3b7c5ac350
commit f36f1efeeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -230,10 +230,26 @@ impl Repl {
let end = Instant::now();
self.print_results(&batches)?;
println!("Query execution complete in {:?}", end - start);
println!(
"Returned {} in {:?}",
Self::row_summary(&batches),
end - start
);
Ok(())
}
fn row_summary<'a>(batches: impl IntoIterator<Item = &'a RecordBatch>) -> String {
let total_rows: usize = batches.into_iter().map(|b| b.num_rows()).sum();
if total_rows > 1 {
format!("{} rows", total_rows)
} else if total_rows == 0 {
"no rows".to_string()
} else {
"1 row".to_string()
}
}
fn use_database(&mut self, db_name: String) {
info!(%db_name, "setting current database");
println!("You are now in remote mode, querying database {}", db_name);

View File

@ -125,7 +125,7 @@ async fn test_sql_use_database() {
.write_stdin(format!("use {};\n\nselect * from cpu;", db_name))
.assert()
.success()
.stdout(predicate::str::contains(expected_output));
.stdout(predicate::str::contains(expected_output).and(predicate::str::contains("1 row")));
}
#[tokio::test]