Skip to content

Allow for inheritance of Query Interface #416

@yatendra-sychedelic

Description

@yatendra-sychedelic

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:

#ifndef CLICKHOUSE_OVERRIDES
#define CLICKHOUSE_OVERRIDES

#include <clickhouse/query.h>

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<void()> callback);

        std::function<void()> _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:

// clickhouse/client.cpp
void Client::Impl::ExecuteQuery(Query query) {
    EnsureNull en(static_cast<QueryEvents*>(&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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions