Skip to main content

uqa_engine/capabilities/
partitions.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Metadata and expression adapters for SQL-owned partition semantics.
8
9use crate::Engine;
10use uqa_core::Value;
11use uqa_sql::semantics::partition::{PartitionCatalog, PartitionContext, PartitionExpressions};
12use uqa_sql::{
13    ast::{ColumnDef, Expr, TableHierarchy},
14    RowSchema, SQLError, SQLParam,
15};
16
17impl Engine {
18    pub(crate) fn partition_context(&self) -> PartitionContext<'_> {
19        PartitionContext {
20            catalog: self,
21            expressions: self,
22            types: self,
23            assignment: self,
24            schema: self,
25        }
26    }
27}
28
29impl PartitionCatalog for Engine {
30    fn try_table_hierarchy(&self, table: &str) -> Result<TableHierarchy, String> {
31        Engine::try_table_hierarchy(self, table).map_err(|error| error.to_string())
32    }
33    fn direct_hierarchy_children(&self, parent: &str) -> Result<Vec<String>, SQLError> {
34        Engine::direct_hierarchy_children(self, parent)
35    }
36    fn try_resolve_table_name(&self, name: &str) -> Result<Option<String>, String> {
37        Engine::try_resolve_table_name(self, name).map_err(|error| error.to_string())
38    }
39    fn try_resolve_table_name_with_control(
40        &self,
41        name: &str,
42        control: &uqa_core::memory::ProductionControl<'_>,
43    ) -> Result<Option<uqa_core::memory::Produced<String>>, SQLError> {
44        self.with_table_state_with_control(name, control, |relation, _| {
45            Ok(relation.qualified_name_with_control(control)?)
46        })
47    }
48    fn try_describe_table(&self, table: &str) -> Result<Option<Vec<ColumnDef>>, String> {
49        Engine::describe_table_in_execution(self, table).map_err(|error| error.to_string())
50    }
51    fn try_table_object_id(&self, table: &str) -> Result<Option<[u8; 16]>, String> {
52        Engine::try_table(self, table)
53            .map(|table| table.map(|table| table.object_id()))
54            .map_err(|error| error.to_string())
55    }
56}
57
58impl PartitionExpressions for Engine {
59    fn expression_text(&self, expression: &Expr) -> Result<String, SQLError> {
60        uqa_execution::catalog::projection::partition_key_expression(
61            &self.catalog_execution(),
62            expression,
63        )
64    }
65    fn evaluate_bound(&self, expression: &Expr, params: &[SQLParam]) -> Result<Value, SQLError> {
66        crate::capabilities::query_expressions::eval_lowered_expression(
67            self, expression, None, params,
68        )
69    }
70    fn evaluate_row(
71        &self,
72        expression: &Expr,
73        row: &dyn uqa_sql::expr::RowLookup,
74        schema: &RowSchema,
75        params: &[SQLParam],
76    ) -> Result<Value, SQLError> {
77        crate::capabilities::query_expressions::eval_lowered_expression_with_schema(
78            self, expression, row, schema, params,
79        )
80    }
81}