|
36 | 36 | #define DBMS_MIN_REVISION_WITH_LOW_CARDINALITY_TYPE 54405 |
37 | 37 | #define DBMS_MIN_REVISION_WITH_COLUMN_DEFAULTS_METADATA 54410 |
38 | 38 | #define DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO 54420 |
| 39 | +#define DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS 54429 |
39 | 40 |
|
40 | | -#define REVISION DBMS_MIN_REVISION_WITH_CLIENT_WRITE_INFO |
| 41 | +#define REVISION DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS |
41 | 42 |
|
42 | 43 | namespace clickhouse { |
43 | 44 |
|
@@ -131,7 +132,7 @@ class Client::Impl { |
131 | 132 |
|
132 | 133 | bool ReceivePacket(uint64_t* server_packet = nullptr); |
133 | 134 |
|
134 | | - void SendQuery(const std::string& query, const std::string& query_id); |
| 135 | + void SendQuery(const Query& query); |
135 | 136 |
|
136 | 137 | void SendData(const Block& block); |
137 | 138 |
|
@@ -230,7 +231,7 @@ void Client::Impl::ExecuteQuery(Query query) { |
230 | 231 | RetryGuard([this]() { Ping(); }); |
231 | 232 | } |
232 | 233 |
|
233 | | - SendQuery(query.GetText(), query.GetQueryID()); |
| 234 | + SendQuery(query); |
234 | 235 |
|
235 | 236 | while (ReceivePacket()) { |
236 | 237 | ; |
@@ -272,7 +273,8 @@ void Client::Impl::Insert(const std::string& table_name, const std::string& quer |
272 | 273 | } |
273 | 274 | } |
274 | 275 |
|
275 | | - SendQuery("INSERT INTO " + table_name + " ( " + fields_section.str() + " ) VALUES", query_id); |
| 276 | + Query query("INSERT INTO " + table_name + " ( " + fields_section.str() + " ) VALUES", query_id); |
| 277 | + SendQuery(query); |
276 | 278 |
|
277 | 279 | uint64_t server_packet; |
278 | 280 | // Receive data packet. |
@@ -608,9 +610,9 @@ void Client::Impl::SendCancel() { |
608 | 610 | output_->Flush(); |
609 | 611 | } |
610 | 612 |
|
611 | | -void Client::Impl::SendQuery(const std::string& query, const std::string& query_id) { |
| 613 | +void Client::Impl::SendQuery(const Query& query) { |
612 | 614 | WireFormat::WriteUInt64(*output_, ClientCodes::Query); |
613 | | - WireFormat::WriteString(*output_, query_id); |
| 615 | + WireFormat::WriteString(*output_, query.GetQueryID()); |
614 | 616 |
|
615 | 617 | /// Client info. |
616 | 618 | if (server_info_.revision >= DBMS_MIN_REVISION_WITH_CLIENT_INFO) { |
@@ -643,15 +645,24 @@ void Client::Impl::SendQuery(const std::string& query, const std::string& query_ |
643 | 645 | } |
644 | 646 | } |
645 | 647 |
|
646 | | - /// Per query settings. |
647 | | - //if (settings) |
648 | | - // settings->serialize(*out); |
649 | | - //else |
| 648 | + /// Per query settings |
| 649 | + if (server_info_.revision >= DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS) { |
| 650 | + for(const auto& [name, field] : query.GetQuerySettings()) { |
| 651 | + WireFormat::WriteString(*output_, name); |
| 652 | + WireFormat::WriteVarint64(*output_, field.flags); |
| 653 | + WireFormat::WriteString(*output_, field.value); |
| 654 | + } |
| 655 | + } |
| 656 | + else if (query.GetQuerySettings().size() > 0) { |
| 657 | + // Current implementation works only for server version >= v20.1.2.4-stable, since we do not implement binary settings serialization. |
| 658 | + throw UnimplementedError(std::string("Can't send query settings to a server, server version is too old")); |
| 659 | + } |
| 660 | + // Empty string signals end of serialized settings |
650 | 661 | WireFormat::WriteString(*output_, std::string()); |
651 | 662 |
|
652 | 663 | WireFormat::WriteUInt64(*output_, Stages::Complete); |
653 | 664 | WireFormat::WriteUInt64(*output_, compression_); |
654 | | - WireFormat::WriteString(*output_, query); |
| 665 | + WireFormat::WriteString(*output_, query.GetText()); |
655 | 666 | // Send empty block as marker of |
656 | 667 | // end of data |
657 | 668 | SendData(Block()); |
|
0 commit comments