Skip to main content

uqa_execution/query/table_functions/
context.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Compose table-function evaluation from live runtime, catalog, routine, and retrieval services.
8
9use crate::operator_tree::runtime::TreeExecutionContext;
10use crate::query::{cypher::CypherTableRuntime, runtime::QueryRuntimeView};
11use crate::routines::invocation::context::RoutineInvocationContext;
12use crate::scalar::plan::PhysicalSubqueryRunner;
13use uqa_core::Value;
14use uqa_operators::OperatorTree;
15use uqa_sql::{
16    ast::OperatorJoinRelations, expr::EngineHook, plan::QueryPlan,
17    semantics::graph_functions::GraphNameCatalog, SQLError, SQLParam, ScalarExpr,
18};
19use uqa_storage::FtsIndexStat;
20
21pub trait TableFunctionSession {
22    fn listening_channels(&self) -> Vec<String>;
23    fn sequence_data(&self, args: &[Value]) -> Result<Value, SQLError>;
24    fn sequence_parameters(&self, args: &[Value]) -> Result<Value, SQLError>;
25    /// The OID of the role with this name in the statement's catalog.
26    fn role_oid(&self, name: &str) -> Result<Option<i64>, SQLError>;
27}
28
29pub trait AnalyzerTableFunctions: crate::query::scalar_projection::AnalyzerRevisions {
30    fn register_named_analyzer(&self, name: &str, config: &str) -> Result<(), String>;
31    fn drop_named_analyzer(&self, name: &str) -> Result<bool, String>;
32    fn list_named_analyzers(&self) -> Result<Vec<String>, String>;
33    fn set_table_field_analyzer(
34        &self,
35        table: &str,
36        field: &str,
37        analyzer: &str,
38        phase: &str,
39    ) -> Result<(), SQLError>;
40    fn fts_index_stats(&self, table: Option<&str>) -> Result<Vec<FtsIndexStat>, SQLError>;
41}
42
43/// Bind both relation operands before execution schedules their independent physical plans.
44pub trait OperatorJoinBinding {
45    fn lower(
46        &self,
47        name: &str,
48        relations: Option<&OperatorJoinRelations>,
49        args: &[ScalarExpr],
50        params: &[SQLParam],
51    ) -> Result<(OperatorJoinRelations, OperatorTree), SQLError>;
52}
53
54pub struct TableFunctionContext<'a> {
55    pub runtime: QueryRuntimeView<'a>,
56    pub session: &'a dyn TableFunctionSession,
57    pub analyzers: &'a dyn AnalyzerTableFunctions,
58    pub graph_names: &'a dyn GraphNameCatalog,
59    pub cypher: &'a dyn CypherTableRuntime,
60    pub routines: RoutineInvocationContext<'a>,
61    pub retrieval: TreeExecutionContext<'a>,
62    pub joins: &'a dyn OperatorJoinBinding,
63    pub params: &'a [SQLParam],
64    pub eval_hook: &'a dyn EngineHook,
65    /// Catalog types and routines for binding argument expressions before evaluation.
66    pub resolver: &'a dyn uqa_sql::FunctionTypeResolver,
67    pub subquery_runner: &'a dyn PhysicalSubqueryRunner,
68    pub subqueries: &'a [QueryPlan],
69}