Skip to content

Commit

Permalink
feat(cli): send write progress (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li authored Jul 28, 2023
1 parent e3e83d4 commit 841387c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
17 changes: 14 additions & 3 deletions cli/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::{
ast::format_query,
config::{OutputFormat, Settings},
helper::CliHelper,
session::QueryKind,
};

#[async_trait::async_trait]
Expand All @@ -42,6 +43,7 @@ pub trait ChunkDisplay {
pub struct FormatDisplay<'a> {
settings: &'a Settings,
query: &'a str,
kind: QueryKind,
// whether replace '\n' with '\\n', only disable in explain/show create stmts
replace_newline: bool,
schema: SchemaRef,
Expand All @@ -68,6 +70,7 @@ impl<'a> FormatDisplay<'a> {
replace_newline,
schema,
data,
kind: QueryKind::from(query),
rows: 0,
progress: None,
start,
Expand Down Expand Up @@ -205,12 +208,20 @@ impl<'a> FormatDisplay<'a> {
if !self.settings.show_stats {
return;
}

if let Some(ref mut stats) = self.stats {
stats.normalize();
let rows_str = if self.rows > 1 { "rows" } else { "row" };

let (rows, kind) = if matches!(self.kind, QueryKind::Update) {
(stats.write_rows, "written")
} else {
(self.rows, "result")
};

let rows_str = if rows > 1 { "rows" } else { "row" };
eprintln!(
"{} {} in {:.3} sec. Processed {} rows, {} ({} rows/s, {}/s)",
self.rows,
"{} {} {kind} in {:.3} sec. Processed {} rows, {} ({} rows/s, {}/s)",
rows,
rows_str,
self.start.elapsed().as_secs_f64(),
humanize_count(stats.total_rows as f64),
Expand Down
6 changes: 3 additions & 3 deletions cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ impl Session {

let start = Instant::now();
let kind = QueryKind::from(query);
match kind {
QueryKind::Update => {
match (kind, is_repl) {
(QueryKind::Update, false) => {
let affected = self.conn.exec(query).await?;
if is_repl {
if affected > 0 {
Expand All @@ -301,7 +301,7 @@ impl Session {
}
Ok(false)
}
QueryKind::Query | QueryKind::Explain => {
_ => {
let replace_newline = replace_newline_in_box_display(query);
let (schema, data) = self.conn.query_iter_ext(query).await?;
let mut displayer = FormatDisplay::new(
Expand Down
3 changes: 3 additions & 0 deletions licenserc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ excludes = [
"core/tests/**",
"driver/tests/**",
"cli/tests/**",

# python files
"**/*.pyi"
]

[properties]
Expand Down

0 comments on commit 841387c

Please sign in to comment.