Execute a WITH query as a pipeline of segments
(
&self,
with_query: &WithQuery,
outer_context: &ExecutionContext,
)
| 1177 | |
| 1178 | /// Execute a WITH query as a pipeline of segments |
| 1179 | fn execute_with_query_with_context( |
| 1180 | &self, |
| 1181 | with_query: &WithQuery, |
| 1182 | outer_context: &ExecutionContext, |
| 1183 | ) -> Result<QueryResult, ExecutionError> { |
| 1184 | log::debug!( |
| 1185 | "Starting WITH query execution with {} segments", |
| 1186 | with_query.segments.len() |
| 1187 | ); |
| 1188 | let mut current_context = outer_context.clone(); |
| 1189 | |
| 1190 | let mut final_results = Vec::new(); |
| 1191 | |
| 1192 | // Execute each query segment in sequence, piping results forward |
| 1193 | for (i, segment) in with_query.segments.iter().enumerate() { |
| 1194 | // Execute MATCH clause for this segment |
| 1195 | let mut segment_results = |
| 1196 | self.execute_match_with_context(&segment.match_clause, ¤t_context)?; |
| 1197 | |
| 1198 | // Apply WHERE clause if present (this is the WHERE clause that comes BEFORE WITH) |
| 1199 | if let Some(where_clause) = &segment.where_clause { |
| 1200 | segment_results = self.apply_where_filter_to_rows( |
| 1201 | segment_results, |
| 1202 | where_clause, |
| 1203 | ¤t_context, |
| 1204 | )?; |
| 1205 | } |
| 1206 | |
| 1207 | // Apply WITH clause to transform and filter results (if present) |
| 1208 | let mut with_results = if let Some(with_clause) = &segment.with_clause { |
| 1209 | log::debug!( |
| 1210 | "Executing WITH clause on {} input rows", |
| 1211 | segment_results.len() |
| 1212 | ); |
| 1213 | self.execute_with_clause(with_clause, segment_results, ¤t_context)? |
| 1214 | } else { |
| 1215 | log::debug!( |
| 1216 | "No WITH clause, passing through {} rows", |
| 1217 | segment_results.len() |
| 1218 | ); |
| 1219 | segment_results |
| 1220 | }; |
| 1221 | |
| 1222 | // Apply UNWIND clause if present (expands lists into rows) |
| 1223 | if let Some(unwind_clause) = &segment.unwind_clause { |
| 1224 | log::debug!("Executing UNWIND clause after WITH"); |
| 1225 | with_results = |
| 1226 | self.execute_unwind_on_rows(unwind_clause, with_results, ¤t_context)?; |
| 1227 | } |
| 1228 | |
| 1229 | // Apply post-UNWIND WHERE clause if present |
| 1230 | if let Some(where_clause) = &segment.post_unwind_where { |
| 1231 | log::debug!("Applying WHERE clause after UNWIND"); |
| 1232 | with_results = self.apply_where_filter_to_rows_vec( |
| 1233 | with_results, |
| 1234 | where_clause, |
| 1235 | ¤t_context, |
| 1236 | )?; |
no test coverage detected