Skip to content

Commit

Permalink
Fix display of execution time (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dandandan committed Jun 6, 2021
1 parent b84789a commit ee2b9ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 3 additions & 4 deletions datafusion-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion datafusion-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(())
}

0 comments on commit ee2b9ef

Please sign in to comment.