Skip to content

Commit

Permalink
feat: Implement bool_and aggregation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed May 30, 2024
1 parent e95b034 commit 65ae176
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/gitql-std/src/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn aggregation_functions() -> &'static HashMap<&'static str, Aggregation> {
map.insert("avg", aggregation_average);
map.insert("count", aggregation_count);
map.insert("group_concat", aggregation_group_concat);
map.insert("bool_and", aggregation_bool_and);
map
})
}
Expand Down Expand Up @@ -81,6 +82,13 @@ pub fn aggregation_function_signatures() -> &'static HashMap<&'static str, Signa
return_type: DataType::Text,
},
);
map.insert(
"bool_and",
Signature {
parameters: vec![DataType::Boolean],
return_type: DataType::Boolean,
},
);
map
})
}
Expand Down Expand Up @@ -137,3 +145,12 @@ pub fn aggregation_group_concat(group_values: Vec<Vec<Value>>) -> Value {
}
Value::Text(string_values.concat())
}

pub fn aggregation_bool_and(group_values: Vec<Vec<Value>>) -> Value {
for row_values in group_values {
if !row_values[0].as_bool() {
return Value::Boolean(false);
}
}
Value::Boolean(true)
}
7 changes: 7 additions & 0 deletions docs/function/aggregations.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ The function group_concat() is an aggregate function that returns a string with

```sql
SELECT GROUP_CONCAT(name, "-", email) FROM commits GROUP BY name;
```

### Aggregation `bool_and`
The function bool_and() is an aggregate function that returns true if all input values are true, otherwise false

```sql
SELECT bool_and(is_remote) FROM branches;
```

0 comments on commit 65ae176

Please sign in to comment.