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
parent
3b7c5ac350
commit
f36f1efeeb
|
@ -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);
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue