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