uqa_engine/capabilities/
cte.rs1use crate::{capabilities::query_scope::CteScope, session::StatementReadSnapshot, Engine};
10use uqa_execution::query::{
11 cte::context::{CteBodyExecutor, CteExecutionContext, QueryOutputRewriter},
12 output::QueryOutput,
13 statement::consumer::QueryOutputMode,
14};
15use uqa_sql::{plan::QueryPlan, SQLError, SQLParam, SQLResult, ScalarExpr};
16
17impl Engine {
18 pub(crate) fn cte_execution_context(&self) -> CteExecutionContext<'_, StatementReadSnapshot> {
19 CteExecutionContext {
20 queries: self,
21 rewrites: self,
22 routines: self,
23 functions: self,
24 runtime: self.query_runtime_view(),
25 }
26 }
27}
28impl CteBodyExecutor<StatementReadSnapshot> for Engine {
29 fn execute_query(
30 &self,
31 query: &QueryPlan,
32 params: &[SQLParam],
33 ctes: &mut CteScope,
34 ) -> Result<QueryOutput, SQLError> {
35 uqa_execution::query::statement::execute_query_plan_output(
36 &self.query_execution_context(),
37 query,
38 params,
39 ctes,
40 QueryOutputMode::SharedSpill,
41 )
42 }
43 fn execute_lateral_query(
44 &self,
45 query: &QueryPlan,
46 outer: &uqa_execution::OwnedPhysicalRow,
47 params: &[SQLParam],
48 ctes: &CteScope,
49 ) -> Result<QueryOutput, SQLError> {
50 uqa_execution::query::sources::lateral_query::execute_lateral_subquery_output(
51 &self.source_execution_context(),
52 query,
53 outer,
54 params,
55 ctes,
56 )
57 }
58 fn execute_command(
59 &self,
60 command: &uqa_planner::CommandPlan,
61 params: &[SQLParam],
62 ctes: &CteScope,
63 ) -> Result<SQLResult, SQLError> {
64 uqa_execution::mutation::entry::execute_cte_command(
65 &self.mutation_entry_context(),
66 command,
67 params,
68 ctes,
69 )
70 }
71 fn fire_after_triggers(
72 &self,
73 queue: &uqa_execution::mutation::triggers::queue::AfterTriggerQueue,
74 ) -> Result<(), SQLError> {
75 queue.fire(&self.trigger_execution_context())
76 }
77}
78impl QueryOutputRewriter for Engine {
79 fn optimize_retained_query(&self, query: &QueryPlan) -> Result<QueryPlan, SQLError> {
80 super::statement_planning::optimize_engine_query(self, query)
81 }
82
83 fn push_output_filter(
84 &self,
85 query: &QueryPlan,
86 qualifier: &str,
87 filter: &ScalarExpr,
88 columns: Option<&[String]>,
89 ) -> Result<Option<QueryPlan>, SQLError> {
90 super::query_planning::push_output_filter_into_query_plan(
91 self, query, qualifier, filter, columns,
92 )
93 }
94}