catalog/system_schema/
utils.rs1use std::sync::Weak;
16
17use common_meta::key::TableMetadataManagerRef;
18use snafu::OptionExt;
19
20use crate::CatalogManager;
21use crate::error::{GetInformationExtensionSnafu, Result, UpgradeWeakCatalogManagerRefSnafu};
22use crate::information_schema::InformationExtensionRef;
23use crate::kvbackend::KvBackendCatalogManager;
24use crate::system_schema::semantic_graph::EntityGraphProviderRef;
25
26pub mod tables;
27
28pub fn entity_graph_provider(
32 catalog_manager: &Weak<dyn CatalogManager>,
33) -> Result<Option<EntityGraphProviderRef>> {
34 let catalog_manager = catalog_manager
35 .upgrade()
36 .context(UpgradeWeakCatalogManagerRefSnafu)?;
37
38 Ok(catalog_manager
39 .as_any()
40 .downcast_ref::<KvBackendCatalogManager>()
41 .and_then(|manager| manager.entity_graph_provider()))
42}
43
44pub fn information_extension(
46 catalog_manager: &Weak<dyn CatalogManager>,
47) -> Result<InformationExtensionRef> {
48 let catalog_manager = catalog_manager
49 .upgrade()
50 .context(UpgradeWeakCatalogManagerRefSnafu)?;
51
52 let information_extension = catalog_manager
53 .as_any()
54 .downcast_ref::<KvBackendCatalogManager>()
55 .map(|manager| manager.information_extension())
56 .context(GetInformationExtensionSnafu)?;
57
58 Ok(information_extension)
59}
60
61pub fn table_meta_manager(
63 catalog_manager: &Weak<dyn CatalogManager>,
64) -> Result<Option<TableMetadataManagerRef>> {
65 let catalog_manager = catalog_manager
66 .upgrade()
67 .context(UpgradeWeakCatalogManagerRefSnafu)?;
68
69 Ok(catalog_manager
70 .as_any()
71 .downcast_ref::<KvBackendCatalogManager>()
72 .map(|manager| manager.table_metadata_manager_ref().clone()))
73}