3838#define DBMS_MIN_REVISION_WITH_DISTRIBUTED_DEPTH 54448
3939#define DBMS_MIN_REVISION_WITH_INITIAL_QUERY_START_TIME 54449
4040#define DBMS_MIN_REVISION_WITH_INCREMENTAL_PROFILE_EVENTS 54451
41+ #define DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS 54453
42+ #define DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION 54454 // Client can get some fields in JSon format
43+ #define DBMS_MIN_PROTOCOL_VERSION_WITH_ADDENDUM 54458 // send quota key after handshake
44+ #define DBMS_MIN_PROTOCOL_REVISION_WITH_QUOTA_KEY 54458 // the same
45+ #define DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS 54459
4146
42- #define DMBS_PROTOCOL_REVISION DBMS_MIN_REVISION_WITH_INCREMENTAL_PROFILE_EVENTS
47+ #define DMBS_PROTOCOL_REVISION DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS
4348
4449namespace clickhouse {
4550
@@ -433,6 +438,11 @@ bool Client::Impl::Handshake() {
433438 if (!ReceiveHello ()) {
434439 return false ;
435440 }
441+
442+ if (server_info_.revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_ADDENDUM) {
443+ WireFormat::WriteString (*output_, std::string ());
444+ }
445+
436446 return true ;
437447}
438448
@@ -502,7 +512,7 @@ bool Client::Impl::ReceivePacket(uint64_t* server_packet) {
502512 return false ;
503513 }
504514 }
505- if constexpr (DMBS_PROTOCOL_REVISION >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO)
515+ if (server_info_. revision >= DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO)
506516 {
507517 if (!WireFormat::ReadUInt64 (*input_, &info.written_rows )) {
508518 return false ;
@@ -589,7 +599,7 @@ bool Client::Impl::ReceivePacket(uint64_t* server_packet) {
589599
590600bool Client::Impl::ReadBlock (InputStream& input, Block* block) {
591601 // Additional information about block.
592- if constexpr (DMBS_PROTOCOL_REVISION >= DBMS_MIN_REVISION_WITH_BLOCK_INFO) {
602+ if (server_info_. revision >= DBMS_MIN_REVISION_WITH_BLOCK_INFO) {
593603 uint64_t num;
594604 BlockInfo info;
595605
@@ -635,6 +645,16 @@ bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
635645 if (!WireFormat::ReadString (input, &type)) {
636646 return false ;
637647 }
648+
649+ if (server_info_.revision >= DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION) {
650+ uint8_t custom_format_len;
651+ if (!WireFormat::ReadFixed (input, &custom_format_len)) {
652+ return false ;
653+ }
654+ if (custom_format_len > 0 ) {
655+ throw UnimplementedError (std::string (" unsupported custom serialization" ));
656+ }
657+ }
638658
639659 if (ColumnRef col = CreateColumnByType (type, create_column_settings)) {
640660 if (num_rows && !col->Load (&input, num_rows)) {
@@ -653,7 +673,7 @@ bool Client::Impl::ReadBlock(InputStream& input, Block* block) {
653673bool Client::Impl::ReceiveData () {
654674 Block block;
655675
656- if constexpr (DMBS_PROTOCOL_REVISION >= DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES) {
676+ if (server_info_. revision >= DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES) {
657677 if (!WireFormat::SkipString (*input_)) {
658678 return false ;
659679 }
@@ -793,6 +813,12 @@ void Client::Impl::SendQuery(const Query& query) {
793813 throw UnimplementedError (std::string (" Can't send open telemetry tracing context to a server, server version is too old" ));
794814 }
795815 }
816+ if (server_info_.revision >= DBMS_MIN_REVISION_WITH_PARALLEL_REPLICAS) {
817+ // replica dont supported by client
818+ WireFormat::WriteUInt64 (*output_, 0 );
819+ WireFormat::WriteUInt64 (*output_, 0 );
820+ WireFormat::WriteUInt64 (*output_, 0 );
821+ }
796822 }
797823
798824 // / Per query settings
@@ -817,6 +843,22 @@ void Client::Impl::SendQuery(const Query& query) {
817843 WireFormat::WriteUInt64 (*output_, Stages::Complete);
818844 WireFormat::WriteUInt64 (*output_, compression_);
819845 WireFormat::WriteString (*output_, query.GetText ());
846+
847+ // Send params after query text
848+ if (server_info_.revision >= DBMS_MIN_PROTOCOL_VERSION_WITH_PARAMETERS) {
849+ for (const auto & [name, value] : query.GetParams ()) {
850+ // params is like query settings
851+ WireFormat::WriteString (*output_, name);
852+ const uint64_t Custom = 2 ;
853+ WireFormat::WriteVarint64 (*output_, Custom);
854+ if (value)
855+ WireFormat::WriteQuotedString (*output_, *value);
856+ else
857+ WireFormat::WriteParamNullRepresentation (*output_);
858+ }
859+ WireFormat::WriteString (*output_, std::string ()); // empty string after last param
860+ }
861+
820862 // Send empty block as marker of
821863 // end of data
822864 SendData (Block ());
@@ -842,6 +884,11 @@ void Client::Impl::WriteBlock(const Block& block, OutputStream& output) {
842884 WireFormat::WriteString (output, bi.Name ());
843885 WireFormat::WriteString (output, bi.Type ()->GetName ());
844886
887+ if (server_info_.revision >= DBMS_MIN_REVISION_WITH_CUSTOM_SERIALIZATION) {
888+ // TODO: custom serialization
889+ WireFormat::WriteFixed<uint8_t >(output, 0 );
890+ }
891+
845892 // Empty columns are not serialized and occupy exactly 0 bytes.
846893 // ref https://github.com/ClickHouse/ClickHouse/blob/39b37a3240f74f4871c8c1679910e065af6bea19/src/Formats/NativeWriter.cpp#L163
847894 const bool containsData = block.GetRowCount () > 0 ;
0 commit comments