Execute a WITH clause to transform query results
(
&self,
with_clause: &WithClause,
input_rows: Vec<Row>,
context: &ExecutionContext,
)
| 1350 | |
| 1351 | /// Execute a WITH clause to transform query results |
| 1352 | fn execute_with_clause( |
| 1353 | &self, |
| 1354 | with_clause: &WithClause, |
| 1355 | input_rows: Vec<Row>, |
| 1356 | context: &ExecutionContext, |
| 1357 | ) -> Result<Vec<Row>, ExecutionError> { |
| 1358 | log::debug!("Executing WITH clause with {} input rows", input_rows.len()); |
| 1359 | |
| 1360 | // DEBUG: Inspect the structure of input rows to understand conversion needs |
| 1361 | if !input_rows.is_empty() { |
| 1362 | log::debug!("DEBUG: execute_with_clause input row sample:"); |
| 1363 | log::debug!( |
| 1364 | " Variables: {:?}", |
| 1365 | input_rows[0].values.keys().collect::<Vec<_>>() |
| 1366 | ); |
| 1367 | for (key, value) in input_rows[0].values.iter() { |
| 1368 | log::debug!(" {}: {:?} (type: {})", key, value, value.type_name()); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | // Separate grouping expressions from aggregate expressions |
| 1373 | let mut grouping_exprs = Vec::new(); |
| 1374 | let mut aggregate_exprs = Vec::new(); |
| 1375 | |
| 1376 | for with_item in &with_clause.items { |
| 1377 | match &with_item.expression { |
| 1378 | Expression::FunctionCall(func_call) => { |
| 1379 | // Check if it's an aggregate function |
| 1380 | match func_call.name.to_lowercase().as_str() { |
| 1381 | "count" | "avg" | "sum" | "min" | "max" => { |
| 1382 | aggregate_exprs.push(with_item); |
| 1383 | } |
| 1384 | _ => { |
| 1385 | grouping_exprs.push(with_item); |
| 1386 | } |
| 1387 | } |
| 1388 | } |
| 1389 | _ => { |
| 1390 | // Non-function expressions are grouping expressions |
| 1391 | grouping_exprs.push(with_item); |
| 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | // COMPREHENSIVE ROUTING CONSOLIDATION: Route ALL WITH clauses through WithClauseProcessor |
| 1397 | // This eliminates the problematic execute_with_clause_simple path entirely |
| 1398 | // Route through WithClauseProcessor |
| 1399 | self.execute_with_clause_via_processor(with_clause, input_rows, context) |
| 1400 | } |
| 1401 | |
| 1402 | /// Execute a WITH clause without aggregation (fallback for simple cases) |
| 1403 | #[allow(dead_code)] // ROADMAP v0.5.0 - Alternative WITH clause implementation |
no test coverage detected