use crate::Engine;
use uqa_core::Value;
use uqa_sql::semantics::partition::{PartitionCatalog, PartitionContext, PartitionExpressions};
use uqa_sql::{
ast::{ColumnDef, Expr, TableHierarchy},
ResultRow, RowSchema, SQLError, SQLParam,
};
impl Engine {
pub(crate) fn partition_context(&self) -> PartitionContext<'_> {
PartitionContext {
catalog: self,
expressions: self,
types: self,
assignment: self,
schema: self,
}
}
}
impl PartitionCatalog for Engine {
fn try_table_hierarchy(&self, table: &str) -> Result<TableHierarchy, String> {
Engine::try_table_hierarchy(self, table).map_err(|error| error.to_string())
}
fn direct_hierarchy_children(&self, parent: &str) -> Result<Vec<String>, SQLError> {
Engine::direct_hierarchy_children(self, parent)
}
fn try_resolve_table_name(&self, name: &str) -> Result<Option<String>, String> {
Engine::try_resolve_table_name(self, name).map_err(|error| error.to_string())
}
fn try_describe_table(&self, table: &str) -> Result<Option<Vec<ColumnDef>>, String> {
Engine::describe_table_in_execution(self, table).map_err(|error| error.to_string())
}
fn try_table_object_id(&self, table: &str) -> Result<Option<[u8; 16]>, String> {
Engine::try_table(self, table)
.map(|table| table.map(|table| table.object_id()))
.map_err(|error| error.to_string())
}
}
impl PartitionExpressions for Engine {
fn expression_text(&self, expression: &Expr) -> Result<String, SQLError> {
uqa_execution::catalog::projection::partition_key_expression(
&self.catalog_execution(),
expression,
)
}
fn evaluate_bound(&self, expression: &Expr, params: &[SQLParam]) -> Result<Value, SQLError> {
crate::capabilities::query_expressions::eval_lowered_expression(
self, expression, None, params,
)
}
fn evaluate_row(
&self,
expression: &Expr,
row: &ResultRow,
schema: &RowSchema,
params: &[SQLParam],
) -> Result<Value, SQLError> {
crate::capabilities::query_expressions::eval_lowered_expression_with_schema(
self, expression, row, schema, params,
)
}
}