Skip to content

Apache DataFusion SQL Query Engine

Fix display of execution time (#514)

Daniël Heresee2b9ef04995
diff --git a/datafusion-cli/src/lib.rs b/datafusion-cli/src/lib.rs
index 5bd16e3330..5b110d3153 100644
--- a/datafusion-cli/src/lib.rs
+++ b/datafusion-cli/src/lib.rs
@@ -29,17 +29,16 @@ pub struct PrintOptions {
fn print_timing_info(row_count: usize, now: Instant) {
println!(
- "{} {} in set. Query took {} seconds.",
+ "{} {} in set. Query took {:.3} seconds.",
row_count,
if row_count == 1 { "row" } else { "rows" },
- now.elapsed().as_secs()
+ now.elapsed().as_secs_f64()
);
}
impl PrintOptions {
/// print the batches to stdout using the specified format
- pub fn print_batches(&self, batches: &[RecordBatch]) -> Result<()> {
- let now = Instant::now();
+ pub fn print_batches(&self, batches: &[RecordBatch], now: Instant) -> Result<()> {
if batches.is_empty() {
if !self.quiet {
print_timing_info(0, now);
diff --git a/datafusion-cli/src/main.rs b/datafusion-cli/src/main.rs
index 083710f6dd..39ce02ffbf 100644
--- a/datafusion-cli/src/main.rs
+++ b/datafusion-cli/src/main.rs
@@ -30,6 +30,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::Path;
+use std::time::Instant;
#[tokio::main]
pub async fn main() {
@@ -238,7 +239,9 @@ async fn exec_and_print(
sql: String,
) -> Result<()> {
let df = ctx.sql(&sql)?;
+ let now = Instant::now();
let results = df.collect().await?;
- print_options.print_batches(&results)?;
+
+ print_options.print_batches(&results, now)?;
Ok(())
}