Execute path traversal with type constraints
(
&self,
path_type: &PathType,
from_variable: &str,
to_variable: &str,
path_elements: &[PathElement],
input_rows: Vec<Row>,
context: &mut Execut
| 6336 | |
| 6337 | /// Execute path traversal with type constraints |
| 6338 | fn execute_path_traversal( |
| 6339 | &self, |
| 6340 | path_type: &PathType, |
| 6341 | from_variable: &str, |
| 6342 | to_variable: &str, |
| 6343 | path_elements: &[PathElement], |
| 6344 | input_rows: Vec<Row>, |
| 6345 | context: &mut ExecutionContext, |
| 6346 | graph: &Arc<GraphCache>, |
| 6347 | ) -> Result<Vec<Row>, ExecutionError> { |
| 6348 | let mut result_rows = Vec::new(); |
| 6349 | |
| 6350 | for input_row in input_rows { |
| 6351 | // Get the starting node |
| 6352 | let start_node_id = input_row.get_value(from_variable).ok_or_else(|| { |
| 6353 | ExecutionError::RuntimeError(format!("Variable not found: {}", from_variable)) |
| 6354 | })?; |
| 6355 | |
| 6356 | if let Value::String(start_id) = start_node_id { |
| 6357 | // Find all paths from start node based on path type |
| 6358 | let paths = self.find_paths_with_constraints( |
| 6359 | start_id, |
| 6360 | path_elements, |
| 6361 | path_type, |
| 6362 | graph, |
| 6363 | context, |
| 6364 | )?; |
| 6365 | |
| 6366 | // Create result rows for each valid path |
| 6367 | for path in paths { |
| 6368 | let mut row = input_row.clone(); |
| 6369 | |
| 6370 | // Add the end node to the row |
| 6371 | if let Some(end_node_id) = path.last() { |
| 6372 | row.set_value(to_variable.to_string(), Value::String(end_node_id.clone())); |
| 6373 | } |
| 6374 | |
| 6375 | // Add intermediate variables if specified |
| 6376 | for (i, element) in path_elements.iter().enumerate() { |
| 6377 | if i < path.len() - 1 { |
| 6378 | row.set_value( |
| 6379 | element.node_variable.clone(), |
| 6380 | Value::String(path[i + 1].clone()), |
| 6381 | ); |
| 6382 | } |
| 6383 | } |
| 6384 | |
| 6385 | result_rows.push(row); |
| 6386 | } |
| 6387 | } |
| 6388 | } |
| 6389 | |
| 6390 | Ok(result_rows) |
| 6391 | } |
| 6392 | |
| 6393 | /// Find paths with type constraints |
| 6394 | fn find_paths_with_constraints( |
no test coverage detected