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 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:
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.
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:subscribe_progress
interfaceBlock
orProgress
.An alternative is to add a method to
Client
to return the ID of the query currently executing; this would be almost trivial.