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