MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / execute_unwind

Method execute_unwind

graphlite/src/exec/executor.rs:9435–9492  ·  view source on GitHub ↗

Execute UNWIND operation

(
        &self,
        expression: &Expression,
        variable: &str,
        input: Option<&PhysicalNode>,
        context: &ExecutionContext,
        graph: Option<&Arc<GraphCache>>,
    )

Source from the content-addressed store, hash-verified

9433
9434 /// Execute UNWIND operation
9435 fn execute_unwind(
9436 &self,
9437 expression: &Expression,
9438 variable: &str,
9439 input: Option<&PhysicalNode>,
9440 context: &ExecutionContext,
9441 graph: Option<&Arc<GraphCache>>,
9442 ) -> Result<Vec<Row>, ExecutionError> {
9443 let mut result_rows = Vec::new();
9444
9445 // Get input rows (if any)
9446 let input_rows = if let Some(input_node) = input {
9447 if let Some(graph_cache) = graph {
9448 let mut mutable_context = context.clone();
9449 self.execute_node_with_graph(input_node, &mut mutable_context, graph_cache)?
9450 } else {
9451 return Err(ExecutionError::RuntimeError(
9452 "UNWIND requires graph context when processing input".to_string(),
9453 ));
9454 }
9455 } else {
9456 // Standalone UNWIND - create a single empty row as context
9457 vec![Row::new()]
9458 };
9459
9460 for input_row in input_rows {
9461 // Evaluate the expression in the context of this input row
9462 let mut row_context = context.clone();
9463
9464 // Add all values from the input row to the context
9465 for (key, value) in &input_row.values {
9466 row_context.set_variable(key.clone(), value.clone());
9467 }
9468
9469 // Evaluate the UNWIND expression
9470 let array_value = self.evaluate_expression(expression, &row_context)?;
9471
9472 // Convert the value to an array and unwind it
9473 match array_value {
9474 Value::Array(elements) => {
9475 // Create a new row for each array element
9476 for element in elements {
9477 let mut new_row = input_row.clone();
9478 new_row.add_value(variable.to_string(), element);
9479 result_rows.push(new_row);
9480 }
9481 }
9482 single_value => {
9483 // If it's not an array, treat it as a single-element array
9484 let mut new_row = input_row.clone();
9485 new_row.add_value(variable.to_string(), single_value);
9486 result_rows.push(new_row);
9487 }
9488 }
9489 }
9490
9491 Ok(result_rows)
9492 }

Callers 1

Calls 5

cloneMethod · 0.80
set_variableMethod · 0.80
add_valueMethod · 0.80
evaluate_expressionMethod · 0.45

Tested by

no test coverage detected