diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 282342ac..67dc5edb 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -73,6 +73,7 @@ jobs: env: # It is impossible to start CH server in docker on macOS due to github actions limitations, # so we use remote server to execute tests, some do not allow some features for anonymoust/free users: - # - system.query_log used by 'Client/ClientCase.Query_ID' - GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*" + # - system.query_log used by 'Client/ClientCase.Query_ID' and 'Client/ClientCase.ClientName' + # - system.opentelemetry_span_log is used by 'Client/ClientCase.TracingContext' + GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*:Client/ClientCase.ClientName/*" run: ./clickhouse-cpp-ut ${GTEST_FILTER} diff --git a/.github/workflows/windows_mingw.yml b/.github/workflows/windows_mingw.yml index 7d7efb34..2315f95a 100644 --- a/.github/workflows/windows_mingw.yml +++ b/.github/workflows/windows_mingw.yml @@ -93,8 +93,9 @@ jobs: env: # It is impossible to start CH server in docker on Windows due to github actions limitations, # so we use remote server to execute tests, some do not allow some features for anonymoust/free users: - # - system.query_log used by 'Client/ClientCase.Query_ID' - GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*" + # - system.query_log used by 'Client/ClientCase.Query_ID' and 'Client/ClientCase.ClientName' + # - system.opentelemetry_span_log is used by 'Client/ClientCase.TracingContext' + GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*:Client/ClientCase.ClientName/*" run: ./build/ut/clickhouse-cpp-ut.exe ${GTEST_FILTER} - name: Test (simple) diff --git a/.github/workflows/windows_msvc.yml b/.github/workflows/windows_msvc.yml index 68172a2a..4c98546e 100644 --- a/.github/workflows/windows_msvc.yml +++ b/.github/workflows/windows_msvc.yml @@ -68,7 +68,8 @@ jobs: env: # It is impossible to start CH server in docker on Windows due to github actions limitations, # so we use remote server to execute tests, some do not allow some features for anonymoust/free users: - # - system.query_log used by 'Client/ClientCase.Query_ID' - GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*" + # - system.query_log used by 'Client/ClientCase.Query_ID' and 'Client/ClientCase.ClientName' + # - system.opentelemetry_span_log is used by 'Client/ClientCase.TracingContext' + GTEST_FILTER: "-Client/ClientCase.Query_ID*:Client/ClientCase.TracingContext/*:Client/ClientCase.ClientName/*" working-directory: ${{github.workspace}}/build/ut run: Release\clickhouse-cpp-ut.exe "${{env.GTEST_FILTER}}" diff --git a/clickhouse/client.cpp b/clickhouse/client.cpp index b41e0ba3..da7f9774 100644 --- a/clickhouse/client.cpp +++ b/clickhouse/client.cpp @@ -17,7 +17,7 @@ #include "base/sslsocket.h" #endif -#define DBMS_NAME "ClickHouse" +#define CLIENT_NAME "clickhouse-cpp" #define DBMS_MIN_REVISION_WITH_TEMPORARY_TABLES 50264 #define DBMS_MIN_REVISION_WITH_TOTAL_ROWS_IN_PROGRESS 51554 @@ -813,7 +813,7 @@ void Client::Impl::SendQuery(const Query& query, bool finalize) { ClientInfo info; info.query_kind = 1; - info.client_name = "ClickHouse client"; + info.client_name = CLIENT_NAME; info.client_version_major = CLICKHOUSE_CPP_VERSION_MAJOR; info.client_version_minor = CLICKHOUSE_CPP_VERSION_MINOR; info.client_version_patch = CLICKHOUSE_CPP_VERSION_PATCH; @@ -978,7 +978,7 @@ void Client::Impl::InitializeStreams(std::unique_ptr&& socket) { bool Client::Impl::SendHello() { WireFormat::WriteUInt64(*output_, ClientCodes::Hello); - WireFormat::WriteString(*output_, std::string(DBMS_NAME) + " client"); + WireFormat::WriteString(*output_, std::string(CLIENT_NAME)); WireFormat::WriteUInt64(*output_, CLICKHOUSE_CPP_VERSION_MAJOR); WireFormat::WriteUInt64(*output_, CLICKHOUSE_CPP_VERSION_MINOR); WireFormat::WriteUInt64(*output_, DMBS_PROTOCOL_REVISION); diff --git a/ut/client_ut.cpp b/ut/client_ut.cpp index ddb0b4ca..27a7c75f 100644 --- a/ut/client_ut.cpp +++ b/ut/client_ut.cpp @@ -1553,3 +1553,30 @@ TEST_P(ClientCase, QueryParameters) { client_->Execute("DROP TEMPORARY TABLE " + table_name); } + +TEST_P(ClientCase, ClientName) { + const auto server_info = client_->GetServerInfo(); + + std::srand(std::time(nullptr) + reinterpret_cast(&server_info)); + const auto * test_info = ::testing::UnitTest::GetInstance()->current_test_info(); + const std::string query_id = std::to_string(std::rand()) + "-" + test_info->test_suite_name() + "/" + test_info->name(); + + SCOPED_TRACE(query_id); + + client_->Select("SELECT 1", query_id, [](const Block&) { /* make sure the data is delivered in full */ }); + + FlushLogs(); + + std::string query_log_query + = "SELECT CAST(client_name, 'String') FROM system.query_log WHERE query_id = '" + query_id + "'"; + + size_t total_rows = 0; + client_->Select(query_log_query, [&total_rows](const Block& block) { + const auto row_count = block.GetRowCount(); + total_rows += row_count; + for (size_t i = 0; i < row_count; ++i) { + ASSERT_EQ(block[0]->AsStrict()->At(i), "clickhouse-cpp"); + } + }); + ASSERT_GT(total_rows, 0UL) << "Query with query_id " << query_id << " is not found"; +}