Skip to content

Commit

Permalink
feat: support display spill file stats
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li committed Jan 7, 2025
1 parent c44caad commit 24faee1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions bindings/nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ impl ServerStats {
}

#[napi(getter)]
pub fn spill_file_count(&self) -> usize {
self.0.spill_file_count
pub fn spill_file_nums(&self) -> usize {
self.0.spill_file_nums
}

#[napi(getter)]
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ impl ServerStats {
self.0.write_bytes
}
#[getter]
pub fn spill_file_count(&self) -> f64 {
self.0.spill_file_count
pub fn spill_file_nums(&self) -> f64 {
self.0.spill_file_nums
}
#[getter]
pub fn running_time_ms(&self) -> f64 {
Expand Down
16 changes: 12 additions & 4 deletions cli/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,12 @@ fn format_read_progress(ss: &ServerStats, elapsed: f64) -> String {
HumanBytes(ss.read_bytes as u64),
HumanBytes(ss.total_bytes as u64),
HumanBytes((ss.read_bytes as f64 / elapsed) as u64),
if ss.spill_file_count > 0 {
format!(", spilled {} files", ss.spill_file_count)
if ss.spill_file_nums > 0 {
format!(
", spilled {} files, {}",
ss.spill_file_nums,
HumanBytes(ss.spill_bytes as u64)
)
} else {
"".to_string()
}
Expand All @@ -432,8 +436,12 @@ pub fn format_write_progress(ss: &ServerStats, elapsed: f64) -> String {
humanize_count(ss.write_rows as f64 / elapsed),
HumanBytes(ss.write_bytes as u64),
HumanBytes((ss.write_bytes as f64 / elapsed) as u64),
if ss.spill_file_count > 0 {
format!(", spilled {} files", ss.spill_file_count)
if ss.spill_file_nums > 0 {
format!(
", spilled {} files, {}",
ss.spill_file_nums,
HumanBytes(ss.spill_bytes as u64)
)
} else {
"".to_string()
}
Expand Down
8 changes: 7 additions & 1 deletion core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Progresses {
pub result_progress: ProgressValues,
// make it optional for backward compatibility
pub total_scan: Option<ProgressValues>,
pub spill_file_count: usize,
pub spill_progress: SpillProgress,
}

impl Progresses {
Expand All @@ -54,6 +54,12 @@ pub struct ProgressValues {
pub bytes: usize,
}

#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct SpillProgress {
pub file_nums: usize,
pub bytes: usize,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SchemaField {
pub name: String,
Expand Down
15 changes: 3 additions & 12 deletions driver/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,10 @@ pub trait Connection: Send + Sync {
Err(e) => (entry.to_string_lossy().to_string(), e.to_string()),
};
let ss = ServerStats {
total_rows: 0,
total_bytes: 0,
read_rows: 0,
read_bytes: 0,
write_rows: total_count,
write_bytes: total_size,
spill_file_count: 0,
running_time_ms: 0.0,

..Default::default()
};
results.push(Ok(RowWithStats::Stats(ss)));
results.push(Ok(RowWithStats::Row(Row::from_vec(
Expand Down Expand Up @@ -256,14 +252,9 @@ pub trait Connection: Send + Sync {
Err(e) => (e.to_string(), 0),
};
let ss = ServerStats {
total_rows: 0,
total_bytes: 0,
read_rows: total_count,
read_bytes: total_size,
spill_file_count: 0,
write_rows: 0,
write_bytes: 0,
running_time_ms: 0.0,
..Default::default()
};
results.push(Ok(RowWithStats::Stats(ss)));
results.push(Ok(RowWithStats::Row(Row::from_vec(
Expand Down
8 changes: 6 additions & 2 deletions sql/src/rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ pub struct ServerStats {
pub running_time_ms: f64,

#[serde(default)]
pub spill_file_count: usize,
pub spill_file_nums: usize,

#[serde(default)]
pub spill_bytes: usize,
}

impl ServerStats {
Expand All @@ -76,7 +79,8 @@ impl From<databend_client::QueryStats> for ServerStats {
read_bytes: stats.progresses.scan_progress.bytes,
write_rows: stats.progresses.write_progress.rows,
write_bytes: stats.progresses.write_progress.bytes,
spill_file_count: stats.progresses.spill_file_count,
spill_file_nums: stats.progresses.spill_progress.file_nums,
spill_bytes: stats.progresses.spill_progress.bytes,
running_time_ms: stats.running_time_ms,
};
if let Some(total) = stats.progresses.total_scan {
Expand Down

0 comments on commit 24faee1

Please sign in to comment.