Skip to main content

uqa_engine/capabilities/statements/
queries.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Retain fresh statement scopes and scoped Engine hooks for native execution.
8
9use crate::{
10    capabilities::{
11        query_scope::{self, CteScope},
12        ScopedEngineHook,
13    },
14    session::StatementReadSnapshot,
15    Engine,
16};
17use uqa_execution::{
18    scalar::plan::PhysicalEvalContext,
19    statement::context::queries::{StatementExpressionOperation, StatementQueryContexts},
20};
21use uqa_sql::catalog::roles::RoleReference;
22use uqa_sql::{SQLError, SQLParam, SQLResult};
23impl StatementQueryContexts<StatementReadSnapshot> for Engine {
24    fn statement_scope(
25        &self,
26        privilege_subject: Option<&RoleReference>,
27    ) -> Result<CteScope, SQLError> {
28        query_scope::new_for_statement(self, privilege_subject)
29    }
30    fn query_context(
31        &self,
32    ) -> uqa_execution::query::statement::context::QueryContext<'_, StatementReadSnapshot> {
33        self.query_execution_context()
34    }
35    fn row_lock_context(
36        &self,
37    ) -> uqa_execution::query::locking::RowLockContext<'_, StatementReadSnapshot> {
38        Engine::row_lock_context(self)
39    }
40    fn with_expression_context(
41        &self,
42        scope: &CteScope,
43        params: &[SQLParam],
44        operation: &mut StatementExpressionOperation<'_>,
45    ) -> Result<SQLResult, SQLError> {
46        let hook = ScopedEngineHook::new(self, scope);
47        let context = PhysicalEvalContext::new(None, params)
48            .with_function_hook(&hook)
49            .with_subquery_runner(&hook);
50        operation(&context)
51    }
52}