Skip to content

Commit ee2b9ef

Browse files
authored
Fix display of execution time (#514)
1 parent b84789a commit ee2b9ef

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

datafusion-cli/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ pub struct PrintOptions {
2929

3030
fn print_timing_info(row_count: usize, now: Instant) {
3131
println!(
32-
"{} {} in set. Query took {} seconds.",
32+
"{} {} in set. Query took {:.3} seconds.",
3333
row_count,
3434
if row_count == 1 { "row" } else { "rows" },
35-
now.elapsed().as_secs()
35+
now.elapsed().as_secs_f64()
3636
);
3737
}
3838

3939
impl PrintOptions {
4040
/// print the batches to stdout using the specified format
41-
pub fn print_batches(&self, batches: &[RecordBatch]) -> Result<()> {
42-
let now = Instant::now();
41+
pub fn print_batches(&self, batches: &[RecordBatch], now: Instant) -> Result<()> {
4342
if batches.is_empty() {
4443
if !self.quiet {
4544
print_timing_info(0, now);

datafusion-cli/src/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use std::fs::File;
3030
use std::io::prelude::*;
3131
use std::io::BufReader;
3232
use std::path::Path;
33+
use std::time::Instant;
3334

3435
#[tokio::main]
3536
pub async fn main() {
@@ -238,7 +239,9 @@ async fn exec_and_print(
238239
sql: String,
239240
) -> Result<()> {
240241
let df = ctx.sql(&sql)?;
242+
let now = Instant::now();
241243
let results = df.collect().await?;
242-
print_options.print_batches(&results)?;
244+
245+
print_options.print_batches(&results, now)?;
243246
Ok(())
244247
}

0 commit comments

Comments
 (0)