Skip to main content

uqa_engine/capabilities/
hierarchy.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Bind hierarchy execution to active metadata and transaction locks.
8use crate::Engine;
9use uqa_execution::schema::hierarchy::{HierarchyCatalog, HierarchyContext, HierarchyNamespace};
10use uqa_sql::{
11    ast::{
12        ColumnDef, ForeignKey, RelationPersistence, TableCheck, TableConstraintSet,
13        TableKeyConstraint, TableLockMode,
14    },
15    SQLError,
16};
17use uqa_storage::StorageBackendResult;
18impl Engine {
19    pub(crate) fn hierarchy_execution_context(&self) -> HierarchyContext<'_> {
20        HierarchyContext {
21            catalog: self,
22            namespace: self,
23            constraints: self.constraint_execution_context(),
24            partitions: self.partition_context(),
25            publication: self.schema_publication_context(),
26            constraint_access: self,
27            constraint_modes: self,
28        }
29    }
30}
31
32impl uqa_execution::schema::hierarchy::detachment::DetachedConstraintModes for Engine {
33    fn preserve_split_modes(
34        &self,
35        retained: &[uqa_sql::catalog::constraints::ConstraintIdentity],
36        detached: &[uqa_sql::schema::inheritance::detachment::ConstraintIdentityChange],
37    ) -> Result<(), SQLError> {
38        if let Some(frame) = self.session.transactions.lock().last_mut() {
39            uqa_sql::schema::inheritance::detachment::preserve_split_constraint_modes(
40                &mut frame.constraint_modes.named,
41                retained,
42                detached,
43            );
44        }
45        self.prune_constraint_modes()
46    }
47}
48impl HierarchyCatalog for Engine {
49    fn try_describe_table(&self, table: &str) -> StorageBackendResult<Option<Vec<ColumnDef>>> {
50        Engine::describe_table_in_execution(self, table)
51    }
52    fn try_check_constraint_definitions(
53        &self,
54        table: &str,
55    ) -> StorageBackendResult<Vec<TableCheck>> {
56        Engine::check_constraint_definitions_in_execution(self, table)
57    }
58    fn try_key_constraints(&self, table: &str) -> StorageBackendResult<Vec<TableKeyConstraint>> {
59        Engine::key_constraints_in_execution(self, table)
60    }
61    fn try_foreign_keys(&self, table: &str) -> StorageBackendResult<Vec<ForeignKey>> {
62        Engine::foreign_keys_in_execution(self, table)
63    }
64    fn try_declared_table_constraints(
65        &self,
66        table: &str,
67    ) -> StorageBackendResult<TableConstraintSet> {
68        Engine::try_declared_table_constraints(self, table)
69    }
70    fn table_persistence(&self, table: &str) -> StorageBackendResult<Option<RelationPersistence>> {
71        Engine::table_persistence(self, table)
72    }
73}
74impl HierarchyNamespace for Engine {
75    fn resolve_visible_relation_kind(
76        &self,
77        name: &str,
78    ) -> Result<uqa_execution::catalog::RelationResolution, SQLError> {
79        Engine::resolve_visible_relation_kind(self, name)
80    }
81    fn lock_relation(&self, table: &str, mode: TableLockMode) -> Result<(), SQLError> {
82        self.lock_relation(table, mode.into())
83    }
84}