ClickHouse / ClickHouse/clickhouse-cpp
Allow for inheritance of Query Interface
- Lenguaje dominante
- C
- Estrellas
- 382
- Forks
- 209
- Merge medio
- 2 d 19 h
- PR fusionados (30 d)
- 14
Descripción
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.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza en clickhouse/client.cpp, en Client::Impl::ExecuteQuery, y sigue cómo se pasa Query a SendQuery y cómo lo gestiona QueryEvents. Compara ese flujo con el ejemplo de herencia y determina cómo se pierde el comportamiento virtual OnFinish de la interfaz. Se considera terminado cuando las implementaciones derivadas de Query pueden recibir el comportamiento de callback previsto durante la ejecución sin romper el uso existente de Query.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- cpp
- Área
- backend-api-design, databases
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100