Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send write progress #174

Merged
merged 4 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading