ClickHouse / ClickHouse/clickhouse-cpp

Allow for inheritance of Query Interface

Aperta
#416 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
C
Stelle
382
Fork
209
Merge medio
1g 22h
PR unite (30g)
13

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start in clickhouse/client.cpp at Client::Impl::ExecuteQuery and trace how Query is passed to SendQuery and handled by QueryEvents. Compare that flow with the inheritance example and determine how the interface's virtual OnFinish behavior is lost. Done means derived Query implementations can receive the intended callback behavior during execution without breaking existing Query use.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
backend-api-design, databases
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.