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

Method evaluate_having_condition

graphlite/src/exec/executor.rs:4080–4134  ·  view source on GitHub ↗

Evaluate HAVING condition with special handling for count(*)

(
        &self,
        condition: &Expression,
        row: &Row,
        context: &mut ExecutionContext,
    )

Source from the content-addressed store, hash-verified

4078
4079 /// Evaluate HAVING condition with special handling for count(*)
4080 fn evaluate_having_condition(
4081 &self,
4082 condition: &Expression,
4083 row: &Row,
4084 context: &mut ExecutionContext,
4085 ) -> Result<bool, ExecutionError> {
4086 // Special handling for binary expressions that contain count(*)
4087 match condition {
4088 Expression::Binary(binary_expr) => {
4089 // Check if left side is count(*)
4090 if let Expression::FunctionCall(func_call) = binary_expr.left.as_ref() {
4091 if func_call.name.to_uppercase() == "COUNT"
4092 && func_call.arguments.len() == 1
4093 && matches!(func_call.arguments[0], Expression::Variable(ref var) if var.name == "*")
4094 {
4095 // Use the computed account_count value instead of evaluating count(*)
4096 let left_value =
4097 if let Some(account_count) = row.values.get("account_count") {
4098 account_count.clone()
4099 } else {
4100 Value::Number(0.0) // Default fallback
4101 };
4102
4103 let _right_value = self.evaluate_expression(&binary_expr.right, context)?;
4104
4105 // Create a temporary variable with the computed account_count value
4106 let temp_var_name = "__temp_count__".to_string();
4107 context.set_variable(temp_var_name.clone(), left_value.clone());
4108
4109 // Create a temporary expression that uses our computed value instead of count(*)
4110 let temp_condition = Expression::Binary(crate::ast::BinaryExpression {
4111 left: Box::new(Expression::Variable(Variable {
4112 name: temp_var_name,
4113 location: Location::default(),
4114 })),
4115 operator: binary_expr.operator.clone(),
4116 right: binary_expr.right.clone(),
4117 location: Location::default(),
4118 });
4119
4120 let result = self.evaluate_expression(&temp_condition, context)?;
4121 return Ok(result.as_boolean().unwrap_or(false));
4122 }
4123 }
4124 // For other binary expressions, evaluate normally
4125 let result = self.evaluate_expression(condition, context)?;
4126 Ok(result.as_boolean().unwrap_or(false))
4127 }
4128 _ => {
4129 // For non-binary expressions, evaluate normally
4130 let result = self.evaluate_expression(condition, context)?;
4131 Ok(result.as_boolean().unwrap_or(false))
4132 }
4133 }
4134 }
4135
4136 /// Execute a projection operation
4137 fn execute_project(

Callers 1

Calls 7

VariableClass · 0.85
cloneMethod · 0.80
set_variableMethod · 0.80
lenMethod · 0.45
getMethod · 0.45
evaluate_expressionMethod · 0.45
as_booleanMethod · 0.45

Tested by

no test coverage detected