risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_description.rs1use std::iter;
16
17use risingwave_common::catalog::RW_CATALOG_SCHEMA_NAME;
18use risingwave_common::types::Fields;
19use risingwave_frontend_macro::system_catalog;
20
21use crate::catalog::system_catalog::SysCatalogReaderImpl;
22use crate::error::Result;
23
24#[derive(Fields)]
25#[primary_key(objoid, classoid, objsubid)]
26struct RwDescription {
27 objoid: i32,
29 classoid: i32,
31 objsubid: Option<i32>,
33 description: Option<String>,
34}
35
36#[system_catalog(table, "rw_catalog.rw_description")]
37fn read(reader: &SysCatalogReaderImpl) -> Result<Vec<RwDescription>> {
38 let build_row =
39 |table_id, catalog_id, index: Option<i32>, description: Option<Box<str>>| RwDescription {
40 objoid: table_id,
41 classoid: catalog_id,
42 objsubid: index,
43 description: description.map(|s| s.into()),
44 };
45
46 let catalog_reader = reader.catalog_reader.read_guard();
47 let rw_catalog =
48 catalog_reader.get_schema_by_name(&reader.auth_context.database, RW_CATALOG_SCHEMA_NAME)?;
49 let schemas = catalog_reader
50 .iter_schemas(&reader.auth_context.database)?
51 .filter(|schema| schema.id() != rw_catalog.id());
52
53 let rw_tables_id: i32 = rw_catalog
54 .get_system_table_by_name("rw_tables")
55 .map(|st| st.id.table_id)
56 .unwrap_or_default() as _;
57
58 Ok(schemas
59 .flat_map(|schema| {
60 schema.iter_user_table().flat_map(|table| {
61 iter::once(build_row(
62 table.id.table_id as _,
63 rw_tables_id,
64 None,
65 table.description.as_deref().map(Into::into),
66 ))
67 .chain(table.columns.iter().map(|col| {
68 build_row(
69 table.id.table_id as _,
70 rw_tables_id,
71 Some(col.column_id().get_id() as _),
72 col.column_desc.description.as_deref().map(Into::into),
73 )
74 }))
75 })
76 })
77 .collect())
78}