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

Method execute_procedure_body_statement

graphlite/src/exec/executor.rs:8719–8790  ·  view source on GitHub ↗

Execute procedure body with chained statements using NEXT

(
        &self,
        procedure_body: &ProcedureBodyStatement,
        context: &mut ExecutionContext,
        graph_expr: Option<&GraphExpression>,
        session: Option<&Arc<std::sync::RwLock<U

Source from the content-addressed store, hash-verified

8717
8718 /// Execute procedure body with chained statements using NEXT
8719 fn execute_procedure_body_statement(
8720 &self,
8721 procedure_body: &ProcedureBodyStatement,
8722 context: &mut ExecutionContext,
8723 graph_expr: Option<&GraphExpression>,
8724 session: Option<&Arc<std::sync::RwLock<UserSession>>>,
8725 ) -> Result<QueryResult, ExecutionError> {
8726 #[allow(unused_assignments)]
8727 let mut last_result = None;
8728 let mut results = Vec::new();
8729
8730 // Execute variable definitions first (if any)
8731 for var_def in &procedure_body.variable_definitions {
8732 let result = self.execute_declare_statement(var_def, context)?;
8733
8734 // Extract variables from DECLARE result and add to context
8735 if let Some(first_row) = result.rows.first() {
8736 for (i, var_name) in result.variables.iter().enumerate() {
8737 if let Some(value) = first_row.positional_values.get(i) {
8738 context.variables.insert(var_name.clone(), value.clone());
8739 }
8740 }
8741 }
8742 results.push(result);
8743 }
8744
8745 // Execute the initial statement with the same context
8746 let initial_result = self.execute_statement(
8747 &procedure_body.initial_statement,
8748 context,
8749 graph_expr,
8750 session,
8751 )?;
8752
8753 // Extract variables from the initial result and add to context for NEXT statements
8754 // This allows RETURN'd variables to be accessible in subsequent segments
8755 if let Some(first_row) = initial_result.rows.first() {
8756 for (var_name, value) in &first_row.values {
8757 context.variables.insert(var_name.clone(), value.clone());
8758 }
8759 }
8760
8761 last_result = Some(initial_result.clone());
8762 results.push(initial_result);
8763
8764 // Execute chained statements with NEXT
8765 for chained in &procedure_body.chained_statements {
8766 // TODO: Handle yield clause if present
8767 if chained.yield_clause.is_some() {
8768 log::warn!("YIELD clause in chained statements not yet implemented");
8769 }
8770
8771 // Pass the SAME context to each statement in the chain
8772 let chained_result =
8773 self.execute_statement(&chained.statement, context, graph_expr, session)?;
8774
8775 // Extract variables from this result for the next segment (if any)
8776 if let Some(first_row) = chained_result.rows.first() {

Callers 1

execute_statementMethod · 0.80

Calls 7

cloneMethod · 0.80
execute_statementMethod · 0.80
firstMethod · 0.45
iterMethod · 0.45
getMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected