Skip to content

Commit

Permalink
fix(cli): stats are missing for update queries (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li authored Dec 6, 2024
1 parent e3b4f69 commit a69b531
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
16 changes: 0 additions & 16 deletions cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,22 +473,6 @@ impl Session {
let _ = self.conn.exec(query).await?;
Ok(None)
}
QueryKind::Update => {
let affected = self.conn.exec(query).await?;
if is_repl {
if affected > 0 {
eprintln!(
"{} rows affected in ({:.3} sec)",
affected,
start.elapsed().as_secs_f64()
);
} else {
eprintln!("processed in ({:.3} sec)", start.elapsed().as_secs_f64());
}
eprintln!();
}
Ok(Some(ServerStats::default()))
}
other => {
let replace_newline = !if self.settings.replace_newline {
false
Expand Down
1 change: 1 addition & 0 deletions cli/tests/http/06-update.result
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
305104
37 changes: 37 additions & 0 deletions cli/tests/http/06-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

cat <<SQL | ${BENDSQL}
CREATE TABLE t3 (
category_id INT NOT NULL,
region_id INT NOT NULL,
user_id BIGINT NOT NULL,
product_id INT NOT NULL,
transaction_date DATETIME NOT NULL,
transaction_amount DECIMAL(10,2) NOT NULL,
discount_amount DECIMAL(10,2) NOT NULL,
is_returned BOOLEAN NOT NULL DEFAULT 0,
inventory_count INT NOT NULL,
last_updated TIMESTAMP NOT NULL
);
create table r like t3 engine = random;
insert into t3 select * from r limit 305104;
SQL


a=`${BENDSQL} --stats --query="""
update t3 set user_id = user_id + 1 where inventory_count % 10 >= 0;
""" 2>&1 | grep -oE '([0-9]+) rows written' | grep -oE '([0-9]+)'`


b=`${BENDSQL} --stats --query="""
update t3 set user_id = user_id + 1 where inventory_count % 10 < 0;
""" 2>&1 | grep -oE '([0-9]+) rows written' | grep -oE '([0-9]+)'`

echo "$[a+b]"


cat <<SQL | ${BENDSQL}
DROP TABLE IF EXISTS t3;
SQL
15 changes: 15 additions & 0 deletions core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ pub struct Progresses {
pub total_scan: Option<ProgressValues>,
}

impl Progresses {
pub fn has_progress(&self) -> bool {
self.scan_progress.bytes > 0
|| self.scan_progress.rows > 0
|| self.write_progress.bytes > 0
|| self.write_progress.rows > 0
|| self.result_progress.bytes > 0
|| self.result_progress.rows > 0
|| self
.total_scan
.as_ref()
.map_or(false, |v| v.bytes > 0 || v.rows > 0)
}
}

#[derive(Debug, Deserialize)]
pub struct ProgressValues {
pub rows: usize,
Expand Down
9 changes: 7 additions & 2 deletions driver/src/rest_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ impl<'o> RestAPIConnection {
}

async fn wait_for_schema(&self, resp: QueryResponse) -> Result<QueryResponse> {
if !resp.data.is_empty() || !resp.schema.is_empty() {
if !resp.data.is_empty() || !resp.schema.is_empty() || resp.stats.progresses.has_progress()
{
return Ok(resp);
}
let node_id = resp.node_id.clone();
Expand All @@ -218,7 +219,11 @@ impl<'o> RestAPIConnection {
.client
.query_page(&result.id, &next_uri, &node_id)
.await?;
if !result.data.is_empty() || !result.schema.is_empty() {

if !result.data.is_empty()
|| !result.schema.is_empty()
|| result.stats.progresses.has_progress()
{
break;
}
}
Expand Down

0 comments on commit a69b531

Please sign in to comment.