add column default_database

This commit is contained in:
万康 2021-08-01 07:51:24 +08:00
parent 99929981ab
commit 66631ca680
5 changed files with 14 additions and 3 deletions

View File

@ -28,7 +28,7 @@ Structure of the `users` section:
<profile>profile_name</profile>
<quota>default</quota>
<default_database>default<default_database>
<databases>
<database_name>
<table_name>

View File

@ -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'] [,...]
```

View File

@ -50,6 +50,7 @@ NamesAndTypesList StorageSystemUsers::getNamesAndTypes()
{"grantees_any", std::make_shared<DataTypeUInt8>()},
{"grantees_list", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
{"grantees_except", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
{"default_database", std::make_shared<DataTypeString>()},
};
return names_and_types;
}
@ -85,6 +86,7 @@ void StorageSystemUsers::fillData(MutableColumns & res_columns, ContextPtr conte
auto & column_grantees_list_offsets = assert_cast<ColumnArray &>(*res_columns[column_index++]).getOffsets();
auto & column_grantees_except = assert_cast<ColumnString &>(assert_cast<ColumnArray &>(*res_columns[column_index]).getData());
auto & column_grantees_except_offsets = assert_cast<ColumnArray &>(*res_columns[column_index++]).getOffsets();
auto & column_default_database = assert_cast<ColumnString &>(*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);
}
}

View File

@ -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;