From ab778eea85c7aa0240c2c128269f7eabe4fdb623 Mon Sep 17 00:00:00 2001 From: August Date: Wed, 13 Nov 2024 16:50:30 +0800 Subject: [PATCH 1/2] fix: fix system acl column type to support `\l` command --- .../src/catalog/system_catalog/mod.rs | 25 ++++++++----------- .../system_catalog/pg_catalog/pg_database.rs | 2 +- .../system_catalog/pg_catalog/pg_namespace.rs | 2 +- .../pg_catalog/pg_tablespace.rs | 2 +- .../rw_catalog/rw_connections.rs | 4 +-- .../system_catalog/rw_catalog/rw_databases.rs | 2 +- .../system_catalog/rw_catalog/rw_functions.rs | 2 +- .../system_catalog/rw_catalog/rw_indexes.rs | 4 +-- .../rw_catalog/rw_internal_tables.rs | 2 +- .../rw_catalog/rw_materialized_views.rs | 2 +- .../system_catalog/rw_catalog/rw_relations.rs | 2 +- .../system_catalog/rw_catalog/rw_schemas.rs | 2 +- .../system_catalog/rw_catalog/rw_secrets.rs | 4 +-- .../system_catalog/rw_catalog/rw_sinks.rs | 2 +- .../system_catalog/rw_catalog/rw_sources.rs | 2 +- .../rw_catalog/rw_subscriptions.rs | 2 +- .../rw_catalog/rw_system_tables.rs | 2 +- .../system_catalog/rw_catalog/rw_tables.rs | 2 +- .../system_catalog/rw_catalog/rw_views.rs | 2 +- 19 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/frontend/src/catalog/system_catalog/mod.rs b/src/frontend/src/catalog/system_catalog/mod.rs index 432266d1871a9..b374567c4372e 100644 --- a/src/frontend/src/catalog/system_catalog/mod.rs +++ b/src/frontend/src/catalog/system_catalog/mod.rs @@ -237,9 +237,8 @@ fn get_acl_items( for_dml_table: bool, users: &Vec, username_map: &HashMap, -) -> String { - let mut res = String::from("{"); - let mut empty_flag = true; +) -> Vec { + let mut res = vec![]; let super_privilege = available_prost_privilege(*object, for_dml_table); for user in users { let privileges = if user.is_super { @@ -263,25 +262,21 @@ fn get_acl_items( }) }); for (granted_by, actions) in grantor_map { - if empty_flag { - empty_flag = false; - } else { - res.push(','); - } - res.push_str(&user.name); - res.push('='); + let mut aclitem = String::new(); + aclitem.push_str(&user.name); + aclitem.push('='); for (action, option) in actions { - res.push_str(&AclMode::from(action).to_string()); + aclitem.push_str(&AclMode::from(action).to_string()); if option { - res.push('*'); + aclitem.push('*'); } } - res.push('/'); + aclitem.push('/'); // should be able to query grantor's name - res.push_str(username_map.get(&granted_by).unwrap()); + aclitem.push_str(username_map.get(&granted_by).unwrap()); + res.push(aclitem); } } - res.push('}'); res } diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_database.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_database.rs index b0510d0244345..183200af8a491 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_database.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_database.rs @@ -58,5 +58,5 @@ struct PgDatabase { datallowconn: bool, datconnlimit: i32, dattablespace: i32, - datacl: String, + datacl: Vec, } diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_namespace.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_namespace.rs index 69506da1ecd67..e01023f75d795 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_namespace.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_namespace.rs @@ -28,5 +28,5 @@ struct PgNamespace { oid: i32, nspname: String, nspowner: i32, - nspacl: String, + nspacl: Vec, } diff --git a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_tablespace.rs b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_tablespace.rs index 81ef923bfa24e..f6d35011a27f1 100644 --- a/src/frontend/src/catalog/system_catalog/pg_catalog/pg_tablespace.rs +++ b/src/frontend/src/catalog/system_catalog/pg_catalog/pg_tablespace.rs @@ -24,6 +24,6 @@ struct PgTablespace { oid: i32, spcname: String, spcowner: i32, - spcacl: String, + spcacl: Vec, spcoptions: String, } diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_connections.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_connections.rs index 2af0b29b16f76..fcc7e8efc3389 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_connections.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_connections.rs @@ -27,7 +27,7 @@ struct RwConnection { owner: i32, type_: String, provider: String, - acl: String, + acl: Vec, } #[system_catalog(table, "rw_catalog.rw_connections")] @@ -44,7 +44,7 @@ fn read_rw_connections(reader: &SysCatalogReaderImpl) -> Result, } #[system_catalog(table, "rw_catalog.rw_databases")] diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_functions.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_functions.rs index 9f002dcab6f16..ce34bfcef42b2 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_functions.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_functions.rs @@ -31,7 +31,7 @@ struct RwFunction { return_type_id: i32, language: String, link: Option, - acl: String, + acl: Vec, always_retry_on_network_error: bool, } diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_indexes.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_indexes.rs index 558e628a3fbfc..b1d42a1ba0c65 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_indexes.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_indexes.rs @@ -29,7 +29,7 @@ struct RwIndex { schema_id: i32, owner: i32, definition: String, - acl: String, + acl: Vec, initialized_at: Option, created_at: Option, initialized_at_cluster_version: Option, @@ -76,7 +76,7 @@ fn read_rw_indexes(reader: &SysCatalogReaderImpl) -> Result> { schema_id: schema.id() as i32, owner: index.index_table.owner as i32, definition: index.index_table.create_sql(), - acl: "".into(), + acl: vec![], initialized_at: index.initialized_at_epoch.map(|e| e.as_timestamptz()), created_at: index.created_at_epoch.map(|e| e.as_timestamptz()), initialized_at_cluster_version: index.initialized_at_cluster_version.clone(), diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_internal_tables.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_internal_tables.rs index 9ea91bfa50731..989226d104a5e 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_internal_tables.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_internal_tables.rs @@ -27,7 +27,7 @@ struct RwInternalTable { schema_id: i32, owner: i32, definition: String, - acl: String, + acl: Vec, initialized_at: Option, created_at: Option, initialized_at_cluster_version: Option, diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_materialized_views.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_materialized_views.rs index a0e8d98b24b69..a1ce41737ab80 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_materialized_views.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_materialized_views.rs @@ -29,7 +29,7 @@ struct RwMaterializedView { owner: i32, definition: String, append_only: bool, - acl: String, + acl: Vec, initialized_at: Option, created_at: Option, initialized_at_cluster_version: Option, diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_relations.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_relations.rs index abe39dbc329a6..a500020e62896 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_relations.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_relations.rs @@ -37,5 +37,5 @@ struct RwRelation { schema_id: i32, owner: i32, definition: String, - acl: String, + acl: Vec, } diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_schemas.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_schemas.rs index 8d8786e0b1098..adaf6563d4aef 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_schemas.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_schemas.rs @@ -26,7 +26,7 @@ struct RwSchema { id: i32, name: String, owner: i32, - acl: String, + acl: Vec, } #[system_catalog(table, "rw_catalog.rw_schemas")] diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_secrets.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_secrets.rs index 09c9a98798e06..33a43c3de51f1 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_secrets.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_secrets.rs @@ -24,7 +24,7 @@ struct RwSecret { id: i32, name: String, owner: i32, - acl: String, + acl: Vec, } #[system_catalog(table, "rw_catalog.rw_secrets")] @@ -38,7 +38,7 @@ fn read_rw_view_info(reader: &SysCatalogReaderImpl) -> Result> { id: secret.id.secret_id() as i32, name: secret.name.clone(), owner: secret.owner as i32, - acl: "".into(), + acl: vec![], }) }) .collect()) diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_sinks.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_sinks.rs index a7bee63805fce..e382a5b7dfaf3 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_sinks.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_sinks.rs @@ -31,7 +31,7 @@ struct RwSink { sink_type: String, connection_id: Option, definition: String, - acl: String, + acl: Vec, initialized_at: Option, created_at: Option, initialized_at_cluster_version: Option, diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_sources.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_sources.rs index 40df3dfc3a849..bdcfe355057a4 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_sources.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_sources.rs @@ -35,7 +35,7 @@ struct RwSource { associated_table_id: Option, connection_id: Option, definition: String, - acl: String, + acl: Vec, initialized_at: Option, created_at: Option, initialized_at_cluster_version: Option, diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_subscriptions.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_subscriptions.rs index 95d22630475ad..c5c1e108e3ef5 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_subscriptions.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_subscriptions.rs @@ -27,7 +27,7 @@ struct RwSubscription { schema_id: i32, owner: i32, definition: String, - acl: String, + acl: Vec, initialized_at: Option, created_at: Option, initialized_at_cluster_version: Option, diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_system_tables.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_system_tables.rs index 0fda14d726876..17d3001e3263c 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_system_tables.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_system_tables.rs @@ -28,7 +28,7 @@ struct SystemTable { schema_id: i32, owner: i32, definition: Option, - acl: String, + acl: Vec, } #[system_catalog(table, "rw_catalog.rw_system_tables")] diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_tables.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_tables.rs index 78416c97b71af..d991315d26b72 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_tables.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_tables.rs @@ -28,7 +28,7 @@ struct RwTable { owner: i32, definition: String, append_only: bool, - acl: String, + acl: Vec, initialized_at: Option, created_at: Option, initialized_at_cluster_version: Option, diff --git a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_views.rs b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_views.rs index 7c156d783a1c3..2141f808362fe 100644 --- a/src/frontend/src/catalog/system_catalog/rw_catalog/rw_views.rs +++ b/src/frontend/src/catalog/system_catalog/rw_catalog/rw_views.rs @@ -27,7 +27,7 @@ struct RwView { schema_id: i32, owner: i32, definition: String, - acl: String, + acl: Vec, } #[system_catalog(table, "rw_catalog.rw_views")] From 672263f9f6010217716c6f8c10294ef78d9a036c Mon Sep 17 00:00:00 2001 From: August Date: Thu, 14 Nov 2024 14:49:31 +0800 Subject: [PATCH 2/2] add slt --- .../batch/catalog/slash_l_database.slt.part | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 e2e_test/batch/catalog/slash_l_database.slt.part diff --git a/e2e_test/batch/catalog/slash_l_database.slt.part b/e2e_test/batch/catalog/slash_l_database.slt.part new file mode 100644 index 0000000000000..1b1d463029cce --- /dev/null +++ b/e2e_test/batch/catalog/slash_l_database.slt.part @@ -0,0 +1,17 @@ +# wrapped test of `\l` command for better consistency. +query T +SELECT count(*) > 0 +FROM +(SELECT + d.datname AS "Name", + pg_catalog.pg_get_userbyid (d.datdba) AS "Owner", + pg_catalog.pg_encoding_to_char (d.encoding) AS "Encoding", + d.datcollate AS "Collate", + d.datctype AS "Ctype", + pg_catalog.array_to_string (d.datacl, E'\n') AS "Access privileges" +FROM + pg_catalog.pg_database AS d +ORDER BY + 1); +---- +t