Evaluate a function call expression
(
&self,
func_call: &FunctionCall,
context: &ExecutionContext,
)
| 5606 | |
| 5607 | /// Evaluate a function call expression |
| 5608 | fn evaluate_function_call( |
| 5609 | &self, |
| 5610 | func_call: &FunctionCall, |
| 5611 | context: &ExecutionContext, |
| 5612 | ) -> Result<Value, ExecutionError> { |
| 5613 | // Check if this is a system procedure call |
| 5614 | if is_system_procedure(&func_call.name) { |
| 5615 | // Evaluate arguments |
| 5616 | let mut evaluated_args = Vec::new(); |
| 5617 | for arg in &func_call.arguments { |
| 5618 | let value = self.evaluate_expression(arg, context)?; |
| 5619 | evaluated_args.push(value); |
| 5620 | } |
| 5621 | |
| 5622 | // Execute system procedure and return the first column of the first row as a value |
| 5623 | // (For more complex use cases, CALL statements should be used instead of function calls) |
| 5624 | let result = self.system_procedures.execute_procedure( |
| 5625 | &func_call.name, |
| 5626 | evaluated_args, |
| 5627 | Some("system"), |
| 5628 | )?; |
| 5629 | if let Some(first_row) = result.rows.first() { |
| 5630 | if let Some(first_value) = first_row.values.values().next() { |
| 5631 | return Ok(first_value.clone()); |
| 5632 | } |
| 5633 | } |
| 5634 | return Ok(Value::Null); |
| 5635 | } |
| 5636 | |
| 5637 | // Get the function from registry |
| 5638 | let function = self.function_registry.get(&func_call.name).ok_or_else(|| { |
| 5639 | ExecutionError::UnsupportedOperator(format!("Function not found: {}", func_call.name)) |
| 5640 | })?; |
| 5641 | |
| 5642 | // Evaluate arguments |
| 5643 | let mut evaluated_args = Vec::new(); |
| 5644 | for arg in &func_call.arguments { |
| 5645 | let value = self.evaluate_expression(arg, context)?; |
| 5646 | evaluated_args.push(value); |
| 5647 | } |
| 5648 | |
| 5649 | // For function calls in projections, we need to create a temporary row set |
| 5650 | // that contains the current context variables as a single row |
| 5651 | let mut temp_row = Row::new(); |
| 5652 | for (key, value) in &context.variables { |
| 5653 | temp_row.values.insert(key.clone(), value.clone()); |
| 5654 | } |
| 5655 | |
| 5656 | // Create function context with the single row and storage access |
| 5657 | let function_context = FunctionContext::with_storage( |
| 5658 | vec![temp_row], |
| 5659 | context.variables.clone(), |
| 5660 | evaluated_args, |
| 5661 | context.storage_manager.clone(), |
| 5662 | context.current_graph.clone(), |
| 5663 | context.get_current_graph_name(), |
| 5664 | ); |
| 5665 |
no test coverage detected