ClickHouse / ClickHouse/clickhouse-cpp
Allow for inheritance of Query Interface
- Dominant language
- C
- Stars
- 382
- Forks
- 209
- Avg merge
- 3h 58m
- Merged PRs (30d)
- 12
Description
Enhancement request.
## Description:
Currently the clickhouse::Query interface cannot be inherited for any requirements which deviate from the existing implementation.
e.g, if we need a callback for when the query is finished, we should be able to override the Query as follows:
```C++
#ifndef CLICKHOUSE_OVERRIDES
#define CLICKHOUSE_OVERRIDES
#include
namespace DB
{
class Query : public clickhouse::Query
{
public:
Query();
Query(const char *query, const char *query_id = nullptr);
Query(const std::string &query, const std::string &query_id = default_query_id);
Query &OnFinish(std::function callback);
std::function _finish_callback;
void OnFinish() override;
private:
};
}
#endif // CLICKHOUSE_OVERRIDES
```
However this does not work and the original function `OnFinish` of clickhouse::Query is called instead of DB::Query.
The culprit as far as I can understand is:
```C++
// clickhouse/client.cpp
void Client::Impl::ExecuteQuery(Query query) {
EnsureNull en(static_cast(&query), &events_);
if (options_.ping_before_query) {
RetryGuard([this]() { Ping(); });
}
SendQuery(query);
while (ReceivePacket()) {
;
}
}
```
Here the function is called without reference and I believe that the compiler is creating a copy of clickhouse::Query with data from the object passed. This causes the overrides from DB::Query to not be called.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.