Summary
Add built-in aggregation functions for common data analysis operations on arrays and collections.
Proposed Functions
| Function |
Description |
Example |
count |
Count elements |
{ users { count } } |
sum |
Sum numeric values |
{ orders { sum(total) } } |
avg |
Average of numeric values |
{ scores { avg(value) } } |
min / max |
Min/max value |
{ prices { min(amount) } } |
sort_by |
Sort elements by field |
{ users { sort_by(age) } } |
group_by |
Group elements by field |
{ logs { group_by(level) } } |
unique |
Deduplicate values |
{ tags { unique } } |
flatten |
Flatten nested arrays |
{ nested_lists { flatten } } |
Example Usage
{
orders(status = "completed") {
count,
sum(total),
avg(total)
}
}
Motivation
These are what people actually need when exploring data from APIs or log files. Without aggregation, users still have to reach for jq or Python for anything analytical. Adding these makes gq a complete data exploration tool from the CLI.
Considerations
- Should aggregations be functions or special query syntax?
- How do aggregations interact with nested queries?
sort_by and group_by need to support ascending/descending and multiple keys
- Type handling: what happens when
sum encounters non-numeric values?
Summary
Add built-in aggregation functions for common data analysis operations on arrays and collections.
Proposed Functions
count{ users { count } }sum{ orders { sum(total) } }avg{ scores { avg(value) } }min/max{ prices { min(amount) } }sort_by{ users { sort_by(age) } }group_by{ logs { group_by(level) } }unique{ tags { unique } }flatten{ nested_lists { flatten } }Example Usage
{ orders(status = "completed") { count, sum(total), avg(total) } }Motivation
These are what people actually need when exploring data from APIs or log files. Without aggregation, users still have to reach for jq or Python for anything analytical. Adding these makes gq a complete data exploration tool from the CLI.
Considerations
sort_byandgroup_byneed to support ascending/descending and multiple keyssumencounters non-numeric values?