Skip to content

Commit 3b31945

Browse files
committed
feat: display default_role in system.users
1 parent 3ef58ce commit 3b31945

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

query/src/storages/system/users_table.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,22 @@ impl AsyncSystemTable for UsersTable {
5252
.iter()
5353
.map(|x| x.auth_info.get_auth_string())
5454
.collect();
55+
let default_roles: Vec<String> = users
56+
.iter()
57+
.map(|x| {
58+
x.option
59+
.default_role()
60+
.clone()
61+
.unwrap_or_else(|| "".to_string())
62+
})
63+
.collect();
5564

5665
Ok(DataBlock::create(self.table_info.schema(), vec![
5766
Series::from_data(names),
5867
Series::from_data(hostnames),
5968
Series::from_data(auth_types),
6069
Series::from_data(auth_strings),
70+
Series::from_data(default_roles),
6171
]))
6272
}
6373
}
@@ -69,6 +79,7 @@ impl UsersTable {
6979
DataField::new("hostname", Vu8::to_data_type()),
7080
DataField::new("auth_type", Vu8::to_data_type()),
7181
DataField::new("auth_string", Vu8::to_data_type()),
82+
DataField::new("default_role", Vu8::to_data_type()),
7283
]);
7384

7485
let table_info = TableInfo {

query/tests/it/storages/system/users_table.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async fn test_users_table() -> Result<()> {
5858
hostname: "%".to_string(),
5959
grants: UserGrantSet::empty(),
6060
quota: UserQuota::no_limit(),
61-
option: UserOption::default(),
61+
option: UserOption::default().with_default_role(Some("role1".to_string())),
6262
},
6363
false,
6464
)
@@ -70,15 +70,15 @@ async fn test_users_table() -> Result<()> {
7070
let stream = table.read(ctx, &source_plan).await?;
7171
let result = stream.try_collect::<Vec<_>>().await?;
7272
let block = &result[0];
73-
assert_eq!(block.num_columns(), 4);
73+
assert_eq!(block.num_columns(), 5);
7474

7575
let expected = vec![
76-
"+-------+-----------+-----------------+------------------------------------------------------------------+",
77-
"| name | hostname | auth_type | auth_string |",
78-
"+-------+-----------+-----------------+------------------------------------------------------------------+",
79-
"| test | localhost | no_password | |",
80-
"| test1 | % | sha256_password | 15e2b0d3c33891ebb0f1ef609ec419420c20e320ce94c65fbc8c3312448eb225 |",
81-
"+-------+-----------+-----------------+------------------------------------------------------------------+",
76+
"+-------+-----------+-----------------+------------------------------------------------------------------+--------------+",
77+
"| name | hostname | auth_type | auth_string | default_role |",
78+
"+-------+-----------+-----------------+------------------------------------------------------------------+--------------+",
79+
"| test | localhost | no_password | | |",
80+
"| test1 | % | sha256_password | 15e2b0d3c33891ebb0f1ef609ec419420c20e320ce94c65fbc8c3312448eb225 | role1 |",
81+
"+-------+-----------+-----------------+------------------------------------------------------------------+--------------+",
8282
];
8383
common_datablocks::assert_blocks_sorted_eq(expected, result.as_slice());
8484
Ok(())

0 commit comments

Comments
 (0)