Skip to content

feat: Aggregation functions #69

Description

@daavidrgz

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions