risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_tables.rs1use risingwave_common::types::{Fields, Timestamptz};
16use risingwave_frontend_macro::system_catalog;
17
18use crate::catalog::system_catalog::{SysCatalogReaderImpl, get_acl_items};
19use crate::error::Result;
20
21#[derive(Fields)]
22struct RwTable {
23 #[primary_key]
24 id: i32,
25 name: String,
26 schema_id: i32,
27 owner: i32,
28 definition: String,
29 append_only: bool,
30 refreshable: bool,
31 acl: Vec<String>,
32 initialized_at: Option<Timestamptz>,
33 created_at: Option<Timestamptz>,
34 initialized_at_cluster_version: Option<String>,
35 created_at_cluster_version: Option<String>,
36}
37
38#[system_catalog(table, "rw_catalog.rw_tables")]
39fn read_rw_table_info(reader: &SysCatalogReaderImpl) -> Result<Vec<RwTable>> {
40 let catalog_reader = reader.catalog_reader.read_guard();
41 let schemas = catalog_reader.iter_schemas(&reader.auth_context.database)?;
42 let user_reader = reader.user_info_reader.read_guard();
43 let users = user_reader.get_all_users();
44 let current_user = user_reader
45 .get_user_by_name(&reader.auth_context.user_name)
46 .expect("user not found");
47 let username_map = user_reader.get_user_name_map();
48
49 Ok(schemas
50 .flat_map(|schema| {
51 schema
52 .iter_user_table_with_acl(current_user)
53 .map(|table| RwTable {
54 id: table.id.as_i32_id(),
55 name: table.name().to_owned(),
56 schema_id: schema.id().as_i32_id(),
57 owner: table.owner as i32,
58 definition: table.create_sql_purified(),
59 append_only: table.append_only,
60 refreshable: table.refreshable,
61 acl: get_acl_items(table.id, true, &users, username_map),
62 initialized_at: table.initialized_at_epoch.map(|e| e.as_timestamptz()),
63 created_at: table.created_at_epoch.map(|e| e.as_timestamptz()),
64 initialized_at_cluster_version: table.initialized_at_cluster_version.clone(),
65 created_at_cluster_version: table.created_at_cluster_version.clone(),
66 })
67 })
68 .collect())
69}