Skip to main content

uqa_engine/capabilities/
batch.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Bind native batch scheduling to the existing session state and cache.
8
9use crate::{session::StatementReadSnapshot, Engine};
10use std::sync::Arc;
11use uqa_execution::statement::{
12    batch::context::{BatchExecutionContext, CachedStatement, StatementCache},
13    context::StatementRuntime,
14};
15use uqa_sql::{SQLError, Statement};
16
17impl Engine {
18    pub(crate) fn batch_execution_context(
19        &self,
20    ) -> BatchExecutionContext<'_, StatementReadSnapshot> {
21        BatchExecutionContext {
22            runtime: StatementRuntime {
23                cancellation: &self.runtime.cancellation,
24                notices: &self.runtime.notices,
25            },
26            persistent_backend: self.storage.backend.is_some(),
27            statements: self,
28            cache: self,
29            aggregates: self,
30            effects: self,
31            planning: self,
32            transactions: self,
33            row_locks: self,
34        }
35    }
36}
37
38impl StatementCache for Engine {
39    fn retire_sql_logical_plan(
40        &self,
41        sql: &str,
42        control: &uqa_core::memory::ProductionControl<'_>,
43    ) -> Result<(), SQLError> {
44        self.session
45            .state
46            .write()
47            .sql_statement_cache
48            .retire_logical(sql, control)
49    }
50
51    fn cached_sql_analysis(
52        &self,
53        sql: &str,
54    ) -> Option<uqa_sql::binding::statements::AnalyzedStatement> {
55        Engine::cached_sql_analysis(self, sql)
56    }
57    fn cache_sql_analysis(
58        &self,
59        sql: &str,
60        analysis: Option<uqa_sql::binding::statements::AnalyzedStatement>,
61        control: &uqa_core::memory::ProductionControl<'_>,
62    ) -> Result<(), SQLError> {
63        Engine::cache_sql_analysis(self, sql, analysis, control)
64    }
65
66    fn cached_sql_statement(&self, sql: &str) -> Option<CachedStatement> {
67        Engine::cached_sql_statement(self, sql).map(|cached| CachedStatement {
68            statement: cached.statement,
69            logical_plan: cached.logical_plan,
70            optimized_plan: cached.optimized_plan,
71            parser: cached.parser,
72        })
73    }
74    fn cache_sql_statement(
75        &self,
76        sql: &str,
77        statement: Arc<Statement>,
78        logical_plan: Option<uqa_sql::plan::SharedExecutablePlan>,
79        parser: uqa_sql::parser::ParserMetadata,
80        control: &uqa_core::memory::ProductionControl<'_>,
81    ) -> Result<(), SQLError> {
82        Engine::cache_sql_statement(self, sql, statement, logical_plan, parser, control)
83    }
84    fn cache_optimized_sql_plan(
85        &self,
86        sql: &str,
87        optimized_plan: uqa_sql::plan::SharedExecutablePlan,
88        control: &uqa_core::memory::ProductionControl<'_>,
89    ) -> Result<(), SQLError> {
90        Engine::cache_optimized_sql_plan(self, sql, optimized_plan, control)
91    }
92}