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

Method evaluate_expression

graphlite/src/exec/executor.rs:4587–4808  ·  view source on GitHub ↗

Evaluate an expression in the given context (legacy method)

(
        &self,
        expr: &Expression,
        context: &ExecutionContext,
    )

Source from the content-addressed store, hash-verified

4585
4586 /// Evaluate an expression in the given context (legacy method)
4587 fn evaluate_expression(
4588 &self,
4589 expr: &Expression,
4590 context: &ExecutionContext,
4591 ) -> Result<Value, ExecutionError> {
4592 match expr {
4593 Expression::Literal(literal) => self.evaluate_literal(literal),
4594
4595 Expression::PropertyAccess(prop_access) => {
4596 // First, try the prefixed property name (for pre-expanded properties)
4597 let var_name = format!("{}.{}", prop_access.object, prop_access.property);
4598 if let Some(value) = context.get_variable(&var_name) {
4599 return Ok(value);
4600 }
4601
4602 // If not found, try to access property from the node variable directly
4603 if let Some(crate::storage::Value::Node(node)) =
4604 context.get_variable(&prop_access.object).as_ref()
4605 {
4606 if let Some(prop_value) = node.properties.get(&prop_access.property) {
4607 return Ok(prop_value.clone());
4608 }
4609 }
4610
4611 // Return NULL if property doesn't exist (SQL standard behavior)
4612 Ok(Value::Null)
4613 }
4614
4615 Expression::Binary(binary) => {
4616 let left_val = self.evaluate_expression(&binary.left, context)?;
4617 let right_val = self.evaluate_expression(&binary.right, context)?;
4618 self.evaluate_binary_op(&binary.operator, left_val, right_val)
4619 }
4620
4621 Expression::Variable(var) => {
4622 // Check both local variables and session parameters
4623 log::debug!(
4624 "Looking for variable '{}' in context with {} variables",
4625 var.name,
4626 context.variables.len()
4627 );
4628 for key in context.variables.keys() {
4629 log::debug!(" Context has variable: '{}'", key);
4630 }
4631 context.get_variable(&var.name).ok_or_else(|| {
4632 ExecutionError::ExpressionError(format!("Variable not found: {}", var.name))
4633 })
4634 }
4635
4636 Expression::FunctionCall(func_call) => self.evaluate_function_call(func_call, context),
4637
4638 Expression::Case(case_expr) => self.evaluate_case_expression(case_expr, context),
4639
4640 Expression::Unary(unary) => {
4641 let operand_val = self.evaluate_expression(&unary.expression, context)?;
4642 self.evaluate_unary_op(&unary.operator, operand_val)
4643 }
4644

Calls 15

evaluate_literalMethod · 0.80
cloneMethod · 0.80
evaluate_binary_opMethod · 0.80
evaluate_unary_opMethod · 0.80
execute_subqueryMethod · 0.80
nextMethod · 0.80
check_subquery_existsMethod · 0.80
values_equalMethod · 0.80

Tested by

no test coverage detected