File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1717#include " base/sslsocket.h"
1818#endif
1919
20- #define DBMS_NAME " ClickHouse "
20+ #define CLIENT_NAME " clickhouse-cpp "
2121
2222#define DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES 50264
2323#define DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS 51554
@@ -813,7 +813,7 @@ void Client::Impl::SendQuery(const Query& query, bool finalize) {
813813 ClientInfo info;
814814
815815 info.query_kind = 1 ;
816- info.client_name = " ClickHouse client " ;
816+ info.client_name = CLIENT_NAME ;
817817 info.client_version_major = CLICKHOUSE_CPP_VERSION_MAJOR;
818818 info.client_version_minor = CLICKHOUSE_CPP_VERSION_MINOR;
819819 info.client_version_patch = CLICKHOUSE_CPP_VERSION_PATCH;
@@ -978,7 +978,7 @@ void Client::Impl::InitializeStreams(std::unique_ptr<SocketBase>&& socket) {
978978
979979bool Client::Impl::SendHello () {
980980 WireFormat::WriteUInt64 (*output_, ClientCodes::Hello);
981- WireFormat::WriteString (*output_, std::string (DBMS_NAME) + " client " );
981+ WireFormat::WriteString (*output_, std::string (CLIENT_NAME) );
982982 WireFormat::WriteUInt64 (*output_, CLICKHOUSE_CPP_VERSION_MAJOR);
983983 WireFormat::WriteUInt64 (*output_, CLICKHOUSE_CPP_VERSION_MINOR);
984984 WireFormat::WriteUInt64 (*output_, DMBS_PROTOCOL_REVISION);
Original file line number Diff line number Diff line change @@ -1553,3 +1553,30 @@ TEST_P(ClientCase, QueryParameters) {
15531553
15541554 client_->Execute (" DROP TEMPORARY TABLE " + table_name);
15551555}
1556+
1557+ TEST_P (ClientCase, ClientName) {
1558+ const auto server_info = client_->GetServerInfo ();
1559+
1560+ std::srand (std::time (nullptr ) + reinterpret_cast <int64_t >(&server_info));
1561+ const auto * test_info = ::testing::UnitTest::GetInstance ()->current_test_info ();
1562+ const std::string query_id = std::to_string (std::rand ()) + " -" + test_info->test_suite_name () + " /" + test_info->name ();
1563+
1564+ SCOPED_TRACE (query_id);
1565+
1566+ client_->Select (" SELECT 1" , query_id, [](const Block&) { /* make sure the data is delivered in full */ });
1567+
1568+ FlushLogs ();
1569+
1570+ std::string query_log_query
1571+ = " SELECT CAST(client_name, 'String') FROM system.query_log WHERE query_id = '" + query_id + " '" ;
1572+
1573+ size_t total_rows = 0 ;
1574+ client_->Select (query_log_query, [&total_rows](const Block& block) {
1575+ const auto row_count = block.GetRowCount ();
1576+ total_rows += row_count;
1577+ for (size_t i = 0 ; i < row_count; ++i) {
1578+ ASSERT_EQ (block[0 ]->AsStrict <ColumnString>()->At (i), " clickhouse-cpp" );
1579+ }
1580+ });
1581+ ASSERT_GT (total_rows, 0UL ) << " Query with query_id " << query_id << " is not found" ;
1582+ }
You can’t perform that action at this time.
0 commit comments