From 66631ca6801528f947a809a832fb9706a3767d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E5=BA=B7?= Date: Sun, 1 Aug 2021 07:51:24 +0800 Subject: [PATCH] add column default_database --- docs/en/operations/settings/settings-users.md | 2 +- docs/en/sql-reference/statements/create/user.md | 1 + src/Storages/System/StorageSystemUsers.cpp | 10 ++++++++-- ...2001_add_default_database_to_system_users.reference | 1 + .../02001_add_default_database_to_system_users.sql | 3 +++ 5 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/02001_add_default_database_to_system_users.reference create mode 100644 tests/queries/0_stateless/02001_add_default_database_to_system_users.sql diff --git a/docs/en/operations/settings/settings-users.md b/docs/en/operations/settings/settings-users.md index ee834dca98a..2c8315ad069 100644 --- a/docs/en/operations/settings/settings-users.md +++ b/docs/en/operations/settings/settings-users.md @@ -28,7 +28,7 @@ Structure of the `users` section: profile_name default - + default diff --git a/docs/en/sql-reference/statements/create/user.md b/docs/en/sql-reference/statements/create/user.md index ea275b9a2f8..dfa065f5d0a 100644 --- a/docs/en/sql-reference/statements/create/user.md +++ b/docs/en/sql-reference/statements/create/user.md @@ -15,6 +15,7 @@ CREATE USER [IF NOT EXISTS | OR REPLACE] name1 [ON CLUSTER cluster_name1] [NOT IDENTIFIED | IDENTIFIED {[WITH {no_password | plaintext_password | sha256_password | sha256_hash | double_sha1_password | double_sha1_hash}] BY {'password' | 'hash'}} | {WITH ldap SERVER 'server_name'} | {WITH kerberos [REALM 'realm']}] [HOST {LOCAL | NAME 'name' | REGEXP 'name_regexp' | IP 'address' | LIKE 'pattern'} [,...] | ANY | NONE] [DEFAULT ROLE role [,...]] + [DEFAULT DATABASE database | NONE] [GRANTEES {user | role | ANY | NONE} [,...] [EXCEPT {user | role} [,...]]] [SETTINGS variable [= value] [MIN [=] min_value] [MAX [=] max_value] [READONLY | WRITABLE] | PROFILE 'profile_name'] [,...] ``` diff --git a/src/Storages/System/StorageSystemUsers.cpp b/src/Storages/System/StorageSystemUsers.cpp index 90b0a914d58..a48e12a1476 100644 --- a/src/Storages/System/StorageSystemUsers.cpp +++ b/src/Storages/System/StorageSystemUsers.cpp @@ -50,6 +50,7 @@ NamesAndTypesList StorageSystemUsers::getNamesAndTypes() {"grantees_any", std::make_shared()}, {"grantees_list", std::make_shared(std::make_shared())}, {"grantees_except", std::make_shared(std::make_shared())}, + {"default_database", std::make_shared()}, }; return names_and_types; } @@ -85,6 +86,7 @@ void StorageSystemUsers::fillData(MutableColumns & res_columns, ContextPtr conte auto & column_grantees_list_offsets = assert_cast(*res_columns[column_index++]).getOffsets(); auto & column_grantees_except = assert_cast(assert_cast(*res_columns[column_index]).getData()); auto & column_grantees_except_offsets = assert_cast(*res_columns[column_index++]).getOffsets(); + auto & column_default_database = assert_cast(*res_columns[column_index++]); auto add_row = [&](const String & name, const UUID & id, @@ -92,7 +94,8 @@ void StorageSystemUsers::fillData(MutableColumns & res_columns, ContextPtr conte const Authentication & authentication, const AllowedClientHosts & allowed_hosts, const RolesOrUsersSet & default_roles, - const RolesOrUsersSet & grantees) + const RolesOrUsersSet & grantees, + const String default_database) { column_name.insertData(name.data(), name.length()); column_id.push_back(id.toUnderType()); @@ -180,6 +183,8 @@ void StorageSystemUsers::fillData(MutableColumns & res_columns, ContextPtr conte for (const auto & except_name : grantees_ast->except_names) column_grantees_except.insertData(except_name.data(), except_name.length()); column_grantees_except_offsets.push_back(column_grantees_except.size()); + + column_default_database.insertData(default_database.data(),default_database.length()); }; for (const auto & id : ids) @@ -192,7 +197,8 @@ void StorageSystemUsers::fillData(MutableColumns & res_columns, ContextPtr conte if (!storage) continue; - add_row(user->getName(), id, storage->getStorageName(), user->authentication, user->allowed_client_hosts, user->default_roles, user->grantees); + add_row(user->getName(), id, storage->getStorageName(), user->authentication, user->allowed_client_hosts, + user->default_roles, user->grantees, user->default_database); } } diff --git a/tests/queries/0_stateless/02001_add_default_database_to_system_users.reference b/tests/queries/0_stateless/02001_add_default_database_to_system_users.reference new file mode 100644 index 00000000000..bec3a35ee8b --- /dev/null +++ b/tests/queries/0_stateless/02001_add_default_database_to_system_users.reference @@ -0,0 +1 @@ +system diff --git a/tests/queries/0_stateless/02001_add_default_database_to_system_users.sql b/tests/queries/0_stateless/02001_add_default_database_to_system_users.sql new file mode 100644 index 00000000000..2952f3fd23e --- /dev/null +++ b/tests/queries/0_stateless/02001_add_default_database_to_system_users.sql @@ -0,0 +1,3 @@ +create user if not exists u_02001 default database system; +select default_database from system.users where name = 'u_02001'; +drop user if exists u_02001; \ No newline at end of file