From 959fe572d7efe3405c209647ca2f29fd6bf26ec7 Mon Sep 17 00:00:00 2001 From: den818 Date: Sun, 9 Oct 2022 16:25:35 +0400 Subject: [PATCH 1/3] Receiving columns metadata --- clickhouse/client.cpp | 16 ++++++++++++++++ clickhouse/protocol.h | 5 +++-- clickhouse/query.h | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/clickhouse/client.cpp b/clickhouse/client.cpp index 36c1bcb3..c11c5d29 100644 --- a/clickhouse/client.cpp +++ b/clickhouse/client.cpp @@ -430,6 +430,22 @@ bool Client::Impl::ReceivePacket(uint64_t* server_packet) { return false; } + case ServerCodes::TableColumns: { + // external table name + if (!WireFormat::SkipString(*input_)) { + return false; + } + + std::string columns_metadata; + if (!WireFormat::ReadString(*input_, &columns_metadata)) { + return false; + } + if (events_) { + events_->OnColumnsMetadata(columns_metadata); + } + return true; + } + default: throw UnimplementedError("unimplemented " + std::to_string((int)packet_type)); break; diff --git a/clickhouse/protocol.h b/clickhouse/protocol.h index dc51f32a..47a76534 100644 --- a/clickhouse/protocol.h +++ b/clickhouse/protocol.h @@ -16,6 +16,7 @@ namespace clickhouse { Extremes = 8, /// Block of mins and maxs, may be compressed. TablesStatusResponse = 9, /// Response to TableStatus. Log = 10, /// Query execution log. + TableColumns = 11, /// Columns' description for default values calculation }; } @@ -23,7 +24,7 @@ namespace clickhouse { namespace ClientCodes { enum { Hello = 0, /// Name, version, default database name. - Query = 1, /** Query id, query settings, query processing stage, + Query = 1, /** Query id, query settings, query processing stage, * compression status, and query text (no INSERT data). */ Data = 2, /// Data `Block` (e.g. INSERT data), may be compressed. @@ -32,7 +33,7 @@ namespace clickhouse { }; } - /// Should we compress `Block`s of data + /// Should we compress `Block`s of data namespace CompressionState { enum { Disable = 0, diff --git a/clickhouse/query.h b/clickhouse/query.h index ae98690d..0f326c40 100644 --- a/clickhouse/query.h +++ b/clickhouse/query.h @@ -66,6 +66,8 @@ class QueryEvents { virtual void OnProgress(const Progress& progress) = 0; + virtual void OnColumnsMetadata(const std::string& columns_metadata) = 0; + virtual void OnFinish() = 0; }; @@ -74,6 +76,7 @@ using ExceptionCallback = std::function; using ProgressCallback = std::function; using SelectCallback = std::function; using SelectCancelableCallback = std::function; +using ColumnsMetadataCallback = std::function; class Query : public QueryEvents { @@ -116,6 +119,12 @@ class Query : public QueryEvents { return *this; } + /// Set handler for receiving a metedata of column of query. + inline Query& OnColumnsMetadata(ColumnsMetadataCallback cb) { + columns_metadata_cb_ = std::move(cb); + return *this; + } + static const std::string default_query_id; private: @@ -149,6 +158,12 @@ class Query : public QueryEvents { } } + void OnColumnsMetadata(const std::string& columns_metadata) override { + if (columns_metadata_cb_) { + columns_metadata_cb_(columns_metadata); + } + } + void OnFinish() override { } @@ -159,6 +174,7 @@ class Query : public QueryEvents { ProgressCallback progress_cb_; SelectCallback select_cb_; SelectCancelableCallback select_cancelable_cb_; + ColumnsMetadataCallback columns_metadata_cb_; }; } From 0600012adeedacc8ea6e1656ad340dd6aaf862b5 Mon Sep 17 00:00:00 2001 From: den818 Date: Sat, 15 Oct 2022 00:26:28 +0400 Subject: [PATCH 2/3] fix --- clickhouse/client.cpp | 7 ++----- clickhouse/query.h | 16 ---------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/clickhouse/client.cpp b/clickhouse/client.cpp index c11c5d29..3bdc83ba 100644 --- a/clickhouse/client.cpp +++ b/clickhouse/client.cpp @@ -436,13 +436,10 @@ bool Client::Impl::ReceivePacket(uint64_t* server_packet) { return false; } - std::string columns_metadata; - if (!WireFormat::ReadString(*input_, &columns_metadata)) { + // columns metadata + if (!WireFormat::SkipString(*input_)) { return false; } - if (events_) { - events_->OnColumnsMetadata(columns_metadata); - } return true; } diff --git a/clickhouse/query.h b/clickhouse/query.h index 0f326c40..ae98690d 100644 --- a/clickhouse/query.h +++ b/clickhouse/query.h @@ -66,8 +66,6 @@ class QueryEvents { virtual void OnProgress(const Progress& progress) = 0; - virtual void OnColumnsMetadata(const std::string& columns_metadata) = 0; - virtual void OnFinish() = 0; }; @@ -76,7 +74,6 @@ using ExceptionCallback = std::function; using ProgressCallback = std::function; using SelectCallback = std::function; using SelectCancelableCallback = std::function; -using ColumnsMetadataCallback = std::function; class Query : public QueryEvents { @@ -119,12 +116,6 @@ class Query : public QueryEvents { return *this; } - /// Set handler for receiving a metedata of column of query. - inline Query& OnColumnsMetadata(ColumnsMetadataCallback cb) { - columns_metadata_cb_ = std::move(cb); - return *this; - } - static const std::string default_query_id; private: @@ -158,12 +149,6 @@ class Query : public QueryEvents { } } - void OnColumnsMetadata(const std::string& columns_metadata) override { - if (columns_metadata_cb_) { - columns_metadata_cb_(columns_metadata); - } - } - void OnFinish() override { } @@ -174,7 +159,6 @@ class Query : public QueryEvents { ProgressCallback progress_cb_; SelectCallback select_cb_; SelectCancelableCallback select_cancelable_cb_; - ColumnsMetadataCallback columns_metadata_cb_; }; } From 51ea715beb85516aac01b75f3ad767b9d84605dc Mon Sep 17 00:00:00 2001 From: den818 Date: Sat, 15 Oct 2022 00:48:20 +0400 Subject: [PATCH 3/3] fix --- clickhouse/client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clickhouse/client.cpp b/clickhouse/client.cpp index 3bdc83ba..209f70c1 100644 --- a/clickhouse/client.cpp +++ b/clickhouse/client.cpp @@ -34,8 +34,9 @@ #define DBMS_MIN_REVISION_WITH_SERVER_DISPLAY_NAME 54372 #define DBMS_MIN_REVISION_WITH_VERSION_PATCH 54401 #define DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE 54405 +#define DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA 54410 -#define REVISION DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE +#define REVISION DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA namespace clickhouse {