Skip to main content

uqa_engine/capabilities/
foreign_catalog.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Borrow pinned foreign definitions, live registry guards and session state for native catalog operations.
8use crate::{Engine, RelationIdentity};
9use std::collections::BTreeMap;
10use uqa_execution::{
11    catalog::foreign::{
12        lookup::{ForeignLookupContext, ForeignLookupState},
13        StoredForeignTable,
14    },
15    schema::foreign_removal::ForeignTableRemovalContext,
16};
17use uqa_storage::StorageBackendResult;
18impl Engine {
19    pub(crate) fn foreign_server_removal_publication(
20        &self,
21    ) -> uqa_execution::schema::foreign_server_removal::ForeignServerRemovalPublication<'_> {
22        uqa_execution::schema::foreign_server_removal::ForeignServerRemovalPublication {
23            registry: self,
24            catalog: self.storage.catalog.as_deref(),
25            changes: self,
26        }
27    }
28    pub(crate) fn foreign_server_removal_context(
29        &self,
30    ) -> uqa_execution::schema::foreign_server_removal::ForeignServerRemovalContext<'_> {
31        uqa_execution::schema::foreign_server_removal::ForeignServerRemovalContext {
32            publication: self.foreign_server_removal_publication(),
33            namespace: self,
34            locks: self,
35            writer: self,
36            roles: self,
37            session: self,
38            deletion: self,
39            notices: self.query_runtime_view().notices,
40        }
41    }
42    pub(crate) fn foreign_lookup_context(&self) -> ForeignLookupContext<'_> {
43        ForeignLookupContext {
44            state: self,
45            registry: self,
46        }
47    }
48    pub(crate) fn foreign_removal_context(&self) -> ForeignTableRemovalContext<'_> {
49        ForeignTableRemovalContext {
50            lookup: self.foreign_lookup_context(),
51            publication: self,
52            catalog: self.storage.catalog.as_deref(),
53            changes: self,
54            events: self.event_lifecycle_context(),
55        }
56    }
57}
58impl ForeignLookupState for Engine {
59    fn query_wrappers(&self) -> Option<&uqa_sql::catalog::foreign_wrapper::ForeignWrappers> {
60        self.query_catalog_snapshot
61            .as_ref()
62            .map(|snapshot| snapshot.foreign_wrappers.as_ref())
63    }
64    fn query_servers(
65        &self,
66    ) -> Option<&BTreeMap<String, uqa_sql::catalog::foreign_server::ForeignServerDefinition>> {
67        self.query_catalog_snapshot
68            .as_ref()
69            .map(|snapshot| snapshot.foreign_servers.as_ref())
70    }
71    fn query_tables(&self) -> Option<&BTreeMap<RelationIdentity, StoredForeignTable>> {
72        self.query_catalog_snapshot
73            .as_ref()
74            .map(|snapshot| snapshot.foreign_tables.as_ref())
75    }
76    fn synchronize_catalog_registries(&self) -> StorageBackendResult<()> {
77        Engine::synchronize_catalog_registries(self)
78    }
79    fn relation_lookup_candidates(
80        &self,
81        name: &str,
82    ) -> StorageBackendResult<Vec<RelationIdentity>> {
83        Engine::relation_lookup_candidates(self, name)
84    }
85}