Execute AT location statement for procedure context Internal method for at location statements
(
&self,
at_stmt: &AtLocationStatement,
context: &mut ExecutionContext,
)
| 8633 | /// Execute AT location statement for procedure context |
| 8634 | /// Internal method for at location statements |
| 8635 | fn execute_at_location_statement( |
| 8636 | &self, |
| 8637 | at_stmt: &AtLocationStatement, |
| 8638 | context: &mut ExecutionContext, |
| 8639 | ) -> Result<QueryResult, ExecutionError> { |
| 8640 | // Set the location context |
| 8641 | let original_graph = self.current_graph(); |
| 8642 | |
| 8643 | // Set the location as current graph context |
| 8644 | let location_graph_expr = GraphExpression::Reference(at_stmt.location_path.clone()); |
| 8645 | self.set_current_graph(location_graph_expr)?; |
| 8646 | |
| 8647 | // Execute all statements in the AT context |
| 8648 | let mut results = Vec::new(); |
| 8649 | let mut last_result: Option<QueryResult> = None; |
| 8650 | for statement in &at_stmt.statements { |
| 8651 | // Special handling for NEXT with YIELD to capture previous result into session |
| 8652 | if let Statement::Next(next_stmt) = statement { |
| 8653 | if next_stmt.target_statement.is_none() { |
| 8654 | if let Some(yield_clause) = &next_stmt.yield_clause { |
| 8655 | if let Some(prev) = &last_result { |
| 8656 | if let Some(first_row) = prev.rows.first() { |
| 8657 | // For each yielded item, pull value from previous result and store in session |
| 8658 | let mut stored = std::collections::HashMap::new(); |
| 8659 | for item in &yield_clause.items { |
| 8660 | let column_name = &item.column_name; |
| 8661 | let output_name = item.alias.as_ref().unwrap_or(column_name); |
| 8662 | // Prefer named lookup; fall back to positional using variables |
| 8663 | let val_opt = |
| 8664 | first_row.values.get(column_name).cloned().or_else(|| { |
| 8665 | prev.variables |
| 8666 | .iter() |
| 8667 | .position(|v| v == column_name) |
| 8668 | .and_then(|idx| { |
| 8669 | first_row.get_value_at_position(idx).cloned() |
| 8670 | }) |
| 8671 | }); |
| 8672 | if let Some(val) = val_opt { |
| 8673 | self.set_session_parameter(output_name, val.clone())?; |
| 8674 | stored.insert(output_name.clone(), val.clone()); |
| 8675 | } |
| 8676 | } |
| 8677 | // Produce a small result showing what was stored |
| 8678 | let row = Row::from_values(stored); |
| 8679 | let result = QueryResult { |
| 8680 | rows: vec![row], |
| 8681 | variables: yield_clause |
| 8682 | .items |
| 8683 | .iter() |
| 8684 | .map(|i| i.alias.as_ref().unwrap_or(&i.column_name).clone()) |
| 8685 | .collect(), |
| 8686 | rows_affected: 1, |
| 8687 | session_result: None, |
| 8688 | warnings: Vec::new(), |
| 8689 | |
| 8690 | execution_time_ms: 0, |
| 8691 | }; |
| 8692 | results.push(result.clone()); |
no test coverage detected