-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a `Client::subscribe_progress` method that allows subscribing to query progress events sent by the server. This is very useful to track the progress of larger queries. The implementation uses a `tokio::sync::broadcast`, which only keeps the most recent events and sends them to subscribers. This was tested through the "basic" example, adapted to display progress, and against a real database. Note that the `Client::query*` interfaces currently do not provide the ID of the query, so it is not yet possible to match progress events against exact queries. Nevertheless, the commit already populates the ID of queries, and returns it as part of the progress stream. Later, The `Client::query*` should likely be adapted to return the query ID in addition to the Block stream. Then either: - We keep the same `subscribe_progress` interface - We return a progress stream for this exact query along with the query ID and the block stream. - We change the stream be a stream of enum representing either `Block` or `Progress`. An alternative is to add a method to `Client` to return the ID of the query currently executing; this would be almost trivial.
- Loading branch information
Showing
4 changed files
with
117 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
#[derive(Debug, Clone, Copy)] | ||
/// Query execution progress. | ||
/// Values are delta and must be summed. | ||
/// | ||
/// See https://clickhouse.com/codebrowser/ClickHouse/src/IO/Progress.h.html | ||
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)] | ||
pub struct Progress { | ||
pub read_rows: u64, | ||
pub read_bytes: u64, | ||
pub new_total_rows_to_read: u64, | ||
pub new_written_rows: Option<u64>, | ||
pub new_written_bytes: Option<u64>, | ||
} | ||
impl std::ops::Add for Progress { | ||
type Output = Progress; | ||
|
||
fn add(self, rhs: Self) -> Self::Output { | ||
let sum_opt = |opt1, opt2| match (opt1, opt2) { | ||
(Some(a), Some(b)) => Some(a + b), | ||
(Some(a), None) => Some(a), | ||
(None, Some(b)) => Some(b), | ||
(None, None) => None, | ||
}; | ||
Self::Output { | ||
read_rows: self.read_rows + rhs.read_rows, | ||
read_bytes: self.read_bytes + rhs.read_bytes, | ||
new_total_rows_to_read: self.new_total_rows_to_read + rhs.new_total_rows_to_read, | ||
new_written_rows: sum_opt(self.new_written_rows, rhs.new_written_rows), | ||
new_written_bytes: sum_opt(self.new_written_bytes, rhs.new_written_bytes), | ||
} | ||
} | ||
} | ||
|
||
impl std::ops::AddAssign for Progress { | ||
fn add_assign(&mut self, rhs: Self) { | ||
*self = *self + rhs; | ||
} | ||
} |