diff --git a/dbms/src/Client/Connection.cpp b/dbms/src/Client/Connection.cpp index 3c6c8d75d0e..9b57c1b39b2 100644 --- a/dbms/src/Client/Connection.cpp +++ b/dbms/src/Client/Connection.cpp @@ -148,6 +148,10 @@ void Connection::receiveHello() { readStringBinary(server_timezone, *in); } + if (server_revision >= DBMS_MIN_REVISION_WITH_SERVER_GROUP_NAME) + { + readStringBinary(server_group_name, *in); + } } else if (packet_type == Protocol::Server::Exception) receiveException()->rethrow(); @@ -203,6 +207,14 @@ const String & Connection::getServerTimezone() return server_timezone; } +const String & Connection::getServerGroupname() +{ + if (!connected) + connect(); + + return server_group_name; +} + void Connection::forceConnected() { if (!connected) diff --git a/dbms/src/Client/Connection.h b/dbms/src/Client/Connection.h index c9b401c91ee..06f8e94e29c 100644 --- a/dbms/src/Client/Connection.h +++ b/dbms/src/Client/Connection.h @@ -134,6 +134,7 @@ public: void getServerVersion(String & name, UInt64 & version_major, UInt64 & version_minor, UInt64 & revision); const String & getServerTimezone(); + const String & getServerGroupname(); /// For log and exception messages. const String & getDescription() const; @@ -213,6 +214,7 @@ private: UInt64 server_version_minor = 0; UInt64 server_revision = 0; String server_timezone; + String server_group_name; std::unique_ptr socket; std::shared_ptr in; diff --git a/dbms/src/Core/Defines.h b/dbms/src/Core/Defines.h index 8b69d83d69e..180d2a0dc2b 100644 --- a/dbms/src/Core/Defines.h +++ b/dbms/src/Core/Defines.h @@ -60,6 +60,7 @@ #define DBMS_MIN_REVISION_WITH_QUOTA_KEY_IN_CLIENT_INFO 54060 #define DBMS_MIN_REVISION_WITH_TABLES_STATUS 54226 #define DBMS_MIN_REVISION_WITH_TIME_ZONE_PARAMETER_IN_DATETIME_DATA_TYPE 54337 +#define DBMS_MIN_REVISION_WITH_SERVER_GROUP_NAME 54355 /// Version of ClickHouse TCP protocol. Set to git tag with latest protocol change. #define DBMS_TCP_PROTOCOL_VERSION 54226 diff --git a/dbms/src/Server/Client.cpp b/dbms/src/Server/Client.cpp index 238be504aac..1189dd4d6bc 100644 --- a/dbms/src/Server/Client.cpp +++ b/dbms/src/Server/Client.cpp @@ -153,6 +153,7 @@ private: /// If the last query resulted in exception. bool got_exception = false; String server_version; + String server_group_name; Stopwatch watch; @@ -425,6 +426,7 @@ private: connection->getServerVersion(server_name, server_version_major, server_version_minor, server_revision); server_version = toString(server_version_major) + "." + toString(server_version_minor) + "." + toString(server_revision); + server_group_name = connection->getServerGroupname(); if (is_interactive) { std::cout << "Connected to " << server_name @@ -450,7 +452,8 @@ private: { String query; String prev_query; - while (char * line_ = readline(query.empty() ? ":) " : ":-] ")) + String prompt = server_group_name.length() ? "[" + server_group_name + "] :) " : ":) "; + while (char * line_ = readline(query.empty() ? prompt.c_str() : ":-] ")) { String line = line_; free(line_); diff --git a/dbms/src/Server/TCPHandler.cpp b/dbms/src/Server/TCPHandler.cpp index 7dadeef966b..70d16d6a16b 100644 --- a/dbms/src/Server/TCPHandler.cpp +++ b/dbms/src/Server/TCPHandler.cpp @@ -508,6 +508,10 @@ void TCPHandler::sendHello() { writeStringBinary(DateLUT::instance().getTimeZone(), *out); } + if (client_revision >= DBMS_MIN_REVISION_WITH_SERVER_GROUP_NAME) + { + writeStringBinary(server.config().getString("group_name"), *out); + } out->next(); } diff --git a/dbms/src/Server/config.xml b/dbms/src/Server/config.xml index e0b4ea563ac..3fe4f580f40 100644 --- a/dbms/src/Server/config.xml +++ b/dbms/src/Server/config.xml @@ -8,7 +8,7 @@ 10 - + staging 8123 9000