Protryon / klickhouse

Rust crate for accessing Clickhouse
Apache License 2.0
92 stars 21 forks source link

Broadcast progress #36

Closed cpg314 closed 10 months ago

cpg314 commented 10 months ago

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. It is pretty short given that the blocks were already parsed.

This was briefly mentioned in https://github.com/Protryon/klickhouse/issues/10#issuecomment-1314082474

Tests

This was tested through the "basic" example, adapted to display progress, and against a real database.

Matching progress against queries

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:

An alternative is to add a method to Client to return the ID of the query currently executing; this would be almost trivial.