(&self, context: &FunctionContext)
| 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" |
nothing calls this directly
no test coverage detected