Execute UNWIND on a set of rows
(
&self,
unwind_clause: &crate::ast::UnwindClause,
input_rows: Vec<Row>,
context: &ExecutionContext,
)
| 7451 | |
| 7452 | /// Execute UNWIND on a set of rows |
| 7453 | fn execute_unwind_on_rows( |
| 7454 | &self, |
| 7455 | unwind_clause: &crate::ast::UnwindClause, |
| 7456 | input_rows: Vec<Row>, |
| 7457 | context: &ExecutionContext, |
| 7458 | ) -> Result<Vec<Row>, ExecutionError> { |
| 7459 | use crate::storage::Value; |
| 7460 | |
| 7461 | let mut output_rows = Vec::new(); |
| 7462 | |
| 7463 | for row in input_rows { |
| 7464 | // Build context with row variables for expression evaluation |
| 7465 | let mut row_context = context.clone(); |
| 7466 | for (key, value) in &row.values { |
| 7467 | row_context.variables.insert(key.clone(), value.clone()); |
| 7468 | } |
| 7469 | |
| 7470 | // Evaluate the UNWIND expression in the context of this row |
| 7471 | let list_value = self.evaluate_expression(&unwind_clause.expression, &row_context)?; |
| 7472 | |
| 7473 | // The expression should evaluate to a list |
| 7474 | let items = match list_value { |
| 7475 | Value::List(items) => items, |
| 7476 | _ => { |
| 7477 | return Err(ExecutionError::RuntimeError(format!( |
| 7478 | "UNWIND expression must evaluate to a list, got: {:?}", |
| 7479 | list_value |
| 7480 | ))); |
| 7481 | } |
| 7482 | }; |
| 7483 | |
| 7484 | // Create a new row for each item in the list |
| 7485 | for item in items { |
| 7486 | let mut new_row = row.clone(); |
| 7487 | new_row.add_value(unwind_clause.variable.clone(), item); |
| 7488 | output_rows.push(new_row); |
| 7489 | } |
| 7490 | } |
| 7491 | |
| 7492 | Ok(output_rows) |
| 7493 | } |
| 7494 | |
| 7495 | /// Apply WHERE filter to a vector of rows |
| 7496 | fn apply_where_filter_to_rows_vec( |
no test coverage detected