risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_views.rs1use risingwave_common::types::Fields;
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 RwView {
23 #[primary_key]
24 id: i32,
25 name: String,
26 schema_id: i32,
27 owner: i32,
28 definition: String,
29 acl: Vec<String>,
30}
31
32#[system_catalog(table, "rw_catalog.rw_views")]
33fn read_rw_view_info(reader: &SysCatalogReaderImpl) -> Result<Vec<RwView>> {
34 let catalog_reader = reader.catalog_reader.read_guard();
35 let schemas = catalog_reader.iter_schemas(&reader.auth_context.database)?;
36 let user_reader = reader.user_info_reader.read_guard();
37 let current_user = user_reader
38 .get_user_by_name(&reader.auth_context.user_name)
39 .expect("user not found");
40 let users = user_reader.get_all_users();
41 let username_map = user_reader.get_user_name_map();
42
43 Ok(schemas
44 .flat_map(|schema| {
45 schema.iter_view_with_acl(current_user).map(|view| RwView {
46 id: view.id.as_i32_id(),
47 name: view.name().to_owned(),
48 schema_id: schema.id().as_i32_id(),
49 owner: view.owner as i32,
50 definition: view.create_sql(schema.name()),
51 acl: get_acl_items(view.id, false, &users, username_map),
52 })
53 })
54 .collect())
55}