clickhouse_arrow/native/
progress.rs1#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
6pub struct Progress {
7 pub read_rows: u64,
8 pub read_bytes: u64,
9 pub total_rows_to_read: u64,
10 pub total_bytes_to_read: Option<u64>,
11 pub written_rows: Option<u64>,
12 pub written_bytes: Option<u64>,
13 pub elapsed_ns: Option<u64>,
14}
15
16impl std::ops::Add for Progress {
17 type Output = Progress;
18
19 fn add(self, rhs: Self) -> Self::Output {
20 let sum_opt = |opt1, opt2| match (opt1, opt2) {
21 (Some(a), Some(b)) => Some(a + b),
22 (Some(a), None) => Some(a),
23 (None, Some(b)) => Some(b),
24 (None, None) => None,
25 };
26 Self::Output {
27 read_rows: self.read_rows + rhs.read_rows,
28 read_bytes: self.read_bytes + rhs.read_bytes,
29 total_rows_to_read: self.total_rows_to_read + rhs.total_rows_to_read,
30 total_bytes_to_read: sum_opt(self.total_bytes_to_read, rhs.total_bytes_to_read),
31 written_rows: sum_opt(self.written_rows, rhs.written_rows),
32 written_bytes: sum_opt(self.written_bytes, rhs.written_bytes),
33 elapsed_ns: sum_opt(self.elapsed_ns, rhs.elapsed_ns),
34 }
35 }
36}
37
38impl std::fmt::Display for Progress {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 write!(f, "Progress | Read | Remaining | W Rows | W Bytes | Elapsed")?;
41
42 let Self {
43 read_rows,
44 read_bytes,
45 total_rows_to_read,
46 total_bytes_to_read: _,
47 written_rows,
48 written_bytes,
49 elapsed_ns,
50 } = self;
51
52 write!(
53 f,
54 "{read_rows}/{read_bytes} | {total_rows_to_read} | {written_rows:?} | \
55 {written_bytes:?} | {elapsed_ns:?}"
56 )?;
57
58 Ok(())
59 }
60}