risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_functions.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 RwFunction {
24 #[primary_key]
25 id: i32,
26 name: String,
27 schema_id: i32,
28 owner: i32,
29 r#type: String,
30 arg_type_ids: Vec<i32>,
31 return_type_id: i32,
32 language: String,
33 link: Option<String>,
34 acl: Vec<String>,
35 always_retry_on_network_error: bool,
36}
37
38#[system_catalog(table, "rw_catalog.rw_functions")]
39fn read(reader: &SysCatalogReaderImpl) -> Result<Vec<RwFunction>> {
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 username_map = user_reader.get_user_name_map();
45
46 Ok(schemas
47 .flat_map(|schema| {
48 schema.iter_function().map(|function| RwFunction {
49 id: function.id.function_id() as i32,
50 name: function.name.clone(),
51 schema_id: schema.id() as i32,
52 owner: function.owner as i32,
53 r#type: function.kind.to_string(),
54 arg_type_ids: function.arg_types.iter().map(|t| t.to_oid()).collect(),
55 return_type_id: function.return_type.to_oid(),
56 language: function.language.clone(),
57 link: function.link.clone(),
58 acl: get_acl_items(
59 &Object::FunctionId(function.id.function_id()),
60 false,
61 &users,
62 username_map,
63 ),
64 always_retry_on_network_error: function.always_retry_on_network_error,
65 })
66 })
67 .collect())
68}