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

Method execute

graphlite/src/functions/aggregate_functions.rs:43–70  ·  view source on GitHub ↗
(&self, context: &FunctionContext)

Source from the content-addressed store, hash-verified

41 }
42
43 fn execute(&self, context: &FunctionContext) -> FunctionResult<Value> {
44 // If no arguments, count all rows
45 if context.argument_count() == 0 {
46 return Ok(Value::Number(context.rows.len() as f64));
47 }
48
49 // If argument provided, count non-null values in that column
50 let column_name = context.get_argument(0)?.as_string().ok_or_else(|| {
51 FunctionError::InvalidArgumentType {
52 message: "COUNT argument must be a string column name".to_string(),
53 }
54 })?;
55
56 // Special case: COUNT(*) should count all rows
57 if column_name == "*" {
58 return Ok(Value::Number(context.rows.len() as f64));
59 }
60
61 let mut count = 0;
62 for row in &context.rows {
63 if let Some(value) = row.values.get(column_name) {
64 if !value.is_null() {
65 count += 1;
66 }
67 }
68 }
69 Ok(Value::Number(count as f64))
70 }
71
72 fn return_type(&self) -> &str {
73 "Number"

Callers

nothing calls this directly

Calls 9

get_argumentMethod · 0.80
is_nullMethod · 0.80
as_numberMethod · 0.80
cloneMethod · 0.80
argument_countMethod · 0.45
lenMethod · 0.45
as_stringMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected