Execute a subquery with correlated variable support
(
&self,
query: &crate::ast::Query,
outer_context: &ExecutionContext,
)
| 1098 | |
| 1099 | /// Execute a subquery with correlated variable support |
| 1100 | fn execute_subquery_with_context( |
| 1101 | &self, |
| 1102 | query: &crate::ast::Query, |
| 1103 | outer_context: &ExecutionContext, |
| 1104 | ) -> Result<QueryResult, ExecutionError> { |
| 1105 | use crate::ast::Query; |
| 1106 | match query { |
| 1107 | Query::Basic(basic_query) => { |
| 1108 | // For basic queries, execute with correlated variable support |
| 1109 | self.execute_basic_query_with_context(basic_query, outer_context) |
| 1110 | } |
| 1111 | Query::SetOperation(set_op) => { |
| 1112 | // Handle set operations by executing recursively |
| 1113 | // TODO: This should also support correlated variables |
| 1114 | // Create a mutable copy of the context for set operation execution |
| 1115 | let mut context_copy = outer_context.clone(); |
| 1116 | self.execute_set_operation(set_op, &mut context_copy) |
| 1117 | } |
| 1118 | Query::Limited { |
| 1119 | query, |
| 1120 | order_clause, |
| 1121 | limit_clause, |
| 1122 | } => { |
| 1123 | // Execute the inner query first, then apply order and limit |
| 1124 | let mut result = self.execute_subquery_with_context(query, outer_context)?; |
| 1125 | |
| 1126 | // Apply ORDER BY if present |
| 1127 | if let Some(order) = order_clause { |
| 1128 | result = self.apply_order_by(result, order, outer_context)?; |
| 1129 | } |
| 1130 | |
| 1131 | // Apply LIMIT if present |
| 1132 | if let Some(limit) = limit_clause { |
| 1133 | result = self.apply_limit(result, limit)?; |
| 1134 | } |
| 1135 | |
| 1136 | Ok(result) |
| 1137 | } |
| 1138 | Query::WithQuery(with_query) => { |
| 1139 | log::warn!("EXECUTE_QUERY_RECURSIVE: WITH query found, executing as pipeline"); |
| 1140 | // Execute WITH query as a pipeline of segments |
| 1141 | self.execute_with_query_with_context(with_query, outer_context) |
| 1142 | } |
| 1143 | Query::Let(let_stmt) => { |
| 1144 | // Execute LET statement with outer context |
| 1145 | // Create a mutable copy since execute_let_statement needs &mut |
| 1146 | let mut context = outer_context.clone(); |
| 1147 | self.execute_let_statement(let_stmt, &mut context) |
| 1148 | } |
| 1149 | Query::For(for_stmt) => { |
| 1150 | // Execute FOR statement with cloned context |
| 1151 | let mut context = outer_context.clone(); |
| 1152 | self.execute_for_statement(for_stmt, &mut context) |
| 1153 | } |
| 1154 | Query::Filter(filter_stmt) => { |
| 1155 | // Execute FILTER statement with cloned context |
| 1156 | let mut context = outer_context.clone(); |
| 1157 | self.execute_filter_statement(filter_stmt, &mut context) |
no test coverage detected