risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_functions.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 RwFunction {
23 #[primary_key]
24 id: i32,
25 name: String,
26 schema_id: i32,
27 owner: i32,
28 r#type: String,
29 arg_type_ids: Vec<i32>,
30 return_type_id: i32,
31 language: String,
32 link: Option<String>,
33 acl: Vec<String>,
34 always_retry_on_network_error: bool,
35 created_at: Option<Timestamptz>,
36 created_at_cluster_version: Option<String>,
37}
38
39#[system_catalog(table, "rw_catalog.rw_functions")]
40fn read(reader: &SysCatalogReaderImpl) -> Result<Vec<RwFunction>> {
41 let catalog_reader = reader.catalog_reader.read_guard();
42 let schemas = catalog_reader.iter_schemas(&reader.auth_context.database)?;
43 let user_reader = reader.user_info_reader.read_guard();
44 let users = user_reader.get_all_users();
45 let current_user = user_reader
46 .get_user_by_name(&reader.auth_context.user_name)
47 .expect("user not found");
48 let username_map = user_reader.get_user_name_map();
49
50 Ok(schemas
51 .flat_map(|schema| {
52 schema
53 .iter_function_with_acl(current_user)
54 .map(|function| RwFunction {
55 id: function.id.as_i32_id(),
56 name: function.name.clone(),
57 schema_id: schema.id().as_i32_id(),
58 owner: function.owner as i32,
59 r#type: function.kind.to_string(),
60 arg_type_ids: function.arg_types.iter().map(|t| t.to_oid()).collect(),
61 return_type_id: function.return_type.to_oid(),
62 language: function.language.clone(),
63 link: function.link.clone(),
64 acl: get_acl_items(function.id, false, &users, username_map),
65 always_retry_on_network_error: function.always_retry_on_network_error,
66 created_at: function.created_at_epoch.map(|e| e.as_timestamptz()),
67 created_at_cluster_version: function.created_at_cluster_version.clone(),
68 })
69 })
70 .collect())
71}