mirror of
https://github.com/hanzo-ds/cpp.git
synced 2026-10-30 20:31:26 +00:00
Pure rename applied on top of upstream tag v2.6.2 (8d2415d6), not HEAD.
The fork was cut at 737145d = v2.6.2-57, which still declared version 2.6.2
in version.h; renaming there would have shipped 57 unreleased commits wearing
a 2.6.2 label. Reset to the tag first so this commit changes names only.
clickhouse/ -> datastore/ (public include root)
namespace clickhouse -> namespace datastore
CLICKHOUSE_CPP_VERSION -> DATASTORE_CPP_VERSION
clickhouse-cpp-lib/-ut -> datastore-cpp-lib/-ut (CMake, Bazel)
CH_MAP_BOOL_TO_UINT8 -> DS_MAP_BOOL_TO_UINT8
CLICKHOUSE_* -> DATASTORE_* (test env vars)
doc links -> docs.hanzo.ai/datastore
This client speaks the NATIVE binary protocol only - there is no HTTP path
and no X-ClickHouse-* header anywhere in it, so the header rename that the
HTTP clients required does not apply and nothing here was broken.
The one string that reaches the wire is CLIENT_NAME, sent by both SendHello
and SendQuery's ClientInfo from a single macro, and it lands in
system.query_log.client_name. Both sites still read the one macro, so they
stay consistent and the server's Hello/Query consistency check is satisfied.
Old rows keep the old name; that is a reporting discontinuity, not a
migration, since nothing keys on it.
CI is repointed at our own server: ghcr.io/hanzoai/datastore:26.2.3.2, the
image production runs. Its entrypoint honours DATASTORE_SKIP_USER_SETUP, not
the CLICKHOUSE_ spelling the compose file used, and its config lives in
/etc/hanzo-datastore-server. ci/docker-compose/config.xml is now layered in
as a config.d drop-in so the image keeps its own white-labelling. That file
and users.xml deliberately keep a <clickhouse> root: it must match the roots
of the drop-ins the image ships, and a mismatch fails silently - the server
logs "Merging bypassed" and starts with every drop-in discarded.
The remote-TLS suites used to default to the third-party host
play.clickhouse.com. They now read DATASTORE_SECURE*_HOST and skip when it is
unset rather than point at a host we do not run.
Dropped as upstream infrastructure with no meaning here: AI_POLICY.md
(upstream's policy about their codebase), .travis.yml (dead CI referencing a
third-party apt repo), cross-repo-bug-relay.yml (relays our issues into an
upstream triage repo). LICENSE keeps its copyright notice, as Apache-2.0
requires.
Verified: cmake configure + 115-target build clean; the full suite is green
against ghcr.io/hanzoai/datastore:26.2.3.2 (894 passed, 0 failed); the
pristine v2.6.2 build run against that same server passes the identical set,
and both logged the same 3914 queries under their respective client names.
247 lines
6.6 KiB
C++
247 lines
6.6 KiB
C++
#pragma once
|
|
|
|
#include "block.h"
|
|
#include "server_exception.h"
|
|
|
|
#include "base/open_telemetry.h"
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
namespace datastore {
|
|
|
|
struct QuerySettingsField {
|
|
enum Flags : uint64_t
|
|
{
|
|
IMPORTANT = 0x01,
|
|
CUSTOM = 0x02,
|
|
OBSOLETE = 0x04,
|
|
};
|
|
std::string value;
|
|
uint64_t flags{0};
|
|
};
|
|
|
|
using QuerySettings = std::unordered_map<std::string, QuerySettingsField>;
|
|
using QueryParamValue = std::optional<std::string>;
|
|
using QueryParams = std::unordered_map<std::string, QueryParamValue>;
|
|
|
|
struct Profile {
|
|
uint64_t rows = 0;
|
|
uint64_t blocks = 0;
|
|
uint64_t bytes = 0;
|
|
uint64_t rows_before_limit = 0;
|
|
bool applied_limit = false;
|
|
bool calculated_rows_before_limit = false;
|
|
};
|
|
|
|
|
|
struct Progress {
|
|
uint64_t rows = 0;
|
|
uint64_t bytes = 0;
|
|
uint64_t total_rows = 0;
|
|
uint64_t written_rows = 0;
|
|
uint64_t written_bytes = 0;
|
|
};
|
|
|
|
|
|
class QueryEvents {
|
|
public:
|
|
virtual ~QueryEvents()
|
|
{ }
|
|
|
|
/// Some data was received.
|
|
virtual void OnData(const Block& block) = 0;
|
|
virtual bool OnDataCancelable(const Block& block) = 0;
|
|
|
|
virtual void OnServerException(const Exception& e) = 0;
|
|
|
|
virtual void OnProfile(const Profile& profile) = 0;
|
|
|
|
virtual void OnProgress(const Progress& progress) = 0;
|
|
|
|
/** Handle query execution logs provided by server.
|
|
* Amount of logs regulated by `send_logs_level` setting.
|
|
* By-default only `fatal` log events are sent to the client side.
|
|
*/
|
|
virtual void OnServerLog(const Block& block) = 0;
|
|
|
|
/// Handle query execution profile events.
|
|
virtual void OnProfileEvents(const Block& block) = 0;
|
|
|
|
virtual void OnFinish() = 0;
|
|
};
|
|
|
|
|
|
using ExceptionCallback = std::function<void(const Exception& e)>;
|
|
using ProgressCallback = std::function<void(const Progress& progress)>;
|
|
using SelectCallback = std::function<void(const Block& block)>;
|
|
using SelectCancelableCallback = std::function<bool(const Block& block)>;
|
|
using SelectServerLogCallback = std::function<bool(const Block& block)>;
|
|
using ProfileEventsCallback = std::function<bool(const Block& block)>;
|
|
using ProfileCallback = std::function<void(const Profile& profile)>;
|
|
|
|
|
|
class Query : public QueryEvents {
|
|
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() override;
|
|
|
|
///
|
|
inline const std::string& GetText() const {
|
|
return query_;
|
|
}
|
|
|
|
inline const std::string& GetQueryID() const {
|
|
return query_id_;
|
|
}
|
|
|
|
inline const QuerySettings& GetQuerySettings() const {
|
|
return query_settings_;
|
|
}
|
|
|
|
/// Set per query settings
|
|
inline Query& SetQuerySettings(QuerySettings query_settings) {
|
|
query_settings_ = std::move(query_settings);
|
|
return *this;
|
|
}
|
|
|
|
/// Set per query setting
|
|
inline Query& SetSetting(const std::string& key, const QuerySettingsField& value) {
|
|
query_settings_[key] = value;
|
|
return *this;
|
|
}
|
|
|
|
inline const QueryParams& GetParams() const { return query_params_; }
|
|
|
|
inline Query& SetParams(QueryParams query_params) {
|
|
query_params_ = std::move(query_params);
|
|
return *this;
|
|
}
|
|
|
|
inline Query& SetParam(const std::string& name, const QueryParamValue& value) {
|
|
query_params_[name] = value;
|
|
return *this;
|
|
}
|
|
|
|
inline const std::optional<open_telemetry::TracingContext>& GetTracingContext() const {
|
|
return tracing_context_;
|
|
}
|
|
|
|
/// Set tracing context for open telemetry signals
|
|
inline Query& SetTracingContext(open_telemetry::TracingContext tracing_context) {
|
|
tracing_context_ = std::move(tracing_context);
|
|
return *this;
|
|
}
|
|
|
|
/// Set handler for receiving result data.
|
|
inline Query& OnData(SelectCallback cb) {
|
|
select_cb_ = std::move(cb);
|
|
return *this;
|
|
}
|
|
|
|
inline Query& OnDataCancelable(SelectCancelableCallback cb) {
|
|
select_cancelable_cb_ = std::move(cb);
|
|
return *this;
|
|
}
|
|
|
|
/// Set handler for receiving server's exception.
|
|
inline Query& OnException(ExceptionCallback cb) {
|
|
exception_cb_ = std::move(cb);
|
|
return *this;
|
|
}
|
|
|
|
/// Set handler for receiving a progress of query execution.
|
|
inline Query& OnProgress(ProgressCallback cb) {
|
|
progress_cb_ = std::move(cb);
|
|
return *this;
|
|
}
|
|
|
|
/// Set handler for receiving a server log of query exceution.
|
|
inline Query& OnServerLog(SelectServerLogCallback cb) {
|
|
select_server_log_cb_ = std::move(cb);
|
|
return *this;
|
|
}
|
|
|
|
/// Set handler for receiving profile events.
|
|
inline Query& OnProfileEvents(ProfileEventsCallback cb) {
|
|
profile_events_callback_cb_ = std::move(cb);
|
|
return *this;
|
|
}
|
|
|
|
inline Query& OnProfile(ProfileCallback cb) {
|
|
profile_callback_cb_ = std::move(cb);
|
|
return *this;
|
|
}
|
|
|
|
static const std::string default_query_id;
|
|
|
|
private:
|
|
void OnData(const Block& block) override {
|
|
if (select_cb_) {
|
|
select_cb_(block);
|
|
}
|
|
}
|
|
|
|
bool OnDataCancelable(const Block& block) override {
|
|
if (select_cancelable_cb_) {
|
|
return select_cancelable_cb_(block);
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
void OnServerException(const Exception& e) override {
|
|
if (exception_cb_) {
|
|
exception_cb_(e);
|
|
}
|
|
}
|
|
|
|
void OnProfile(const Profile& profile) override {
|
|
if (profile_callback_cb_)
|
|
profile_callback_cb_(profile);
|
|
}
|
|
|
|
void OnProgress(const Progress& progress) override {
|
|
if (progress_cb_) {
|
|
progress_cb_(progress);
|
|
}
|
|
}
|
|
|
|
void OnServerLog(const Block& block) override {
|
|
if (select_server_log_cb_) {
|
|
select_server_log_cb_(block);
|
|
}
|
|
}
|
|
|
|
void OnProfileEvents(const Block& block) override {
|
|
if (profile_events_callback_cb_) {
|
|
profile_events_callback_cb_(block);
|
|
}
|
|
}
|
|
|
|
void OnFinish() override {
|
|
}
|
|
|
|
private:
|
|
std::string query_;
|
|
std::string query_id_;
|
|
std::optional<open_telemetry::TracingContext> tracing_context_;
|
|
QuerySettings query_settings_;
|
|
QueryParams query_params_;
|
|
ExceptionCallback exception_cb_;
|
|
ProgressCallback progress_cb_;
|
|
SelectCallback select_cb_;
|
|
SelectCancelableCallback select_cancelable_cb_;
|
|
SelectServerLogCallback select_server_log_cb_;
|
|
ProfileEventsCallback profile_events_callback_cb_;
|
|
ProfileCallback profile_callback_cb_;
|
|
};
|
|
|
|
}
|