Skip to content

docs(zql): document aggregates - #333

Open
arv wants to merge 1 commit into
mainfrom
arv/docs-aggregates-1.12
Open

arv wants to merge 1 commit into
mainfrom
arv/docs-aggregates-1.12

Conversation

@arv

@arv arv commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Do not merge before Zero 1.12 is released. Aggregates, distinct() and groupBy() are not in a released Zero version yet. Keep this a draft until then.

Re-lands #328, which merged too early and was reverted in #331. The change to contents/docs/zql.mdx is identical to #328.

Adds an Aggregates section to the ZQL page covering count(), sum(), avg(), min(), and max() on queries and relationships:

  • A top-level aggregate returns a single value. On a relationship, each row gets the value in place of the related rows.
  • Only the result is synced, and it stays up to date as rows change.
  • where(), start(), and limit() apply before the aggregate, as in SQL.
  • Column types, empty results (0 for count(), null otherwise), and which aggregates update immediately when a mutator runs.

It also adds Distinct and Group By subsections, for distinct() and groupBy(...).count()/sum()/avg()/min()/max():

  • distinct() returns one row per combination of its columns, and distinct().count() counts them, with null counted as a value, unlike SQL's COUNT(DISTINCT).
  • groupBy() returns one row per group with the aggregate under the function's name. null forms a group, and rows are ordered by the grouped columns only.
  • What they don't support yet: limit(), start(), one(), related(), a further aggregate, use in related()/whereExists(), JSON group columns, and ordering by the aggregate.
  • Which ones update immediately when a mutator runs.

Also regenerates assets/search-index.json. It will conflict in that file with the JSON filters docs PR; whichever lands second needs the index regenerated. The roadmap and status pages still list aggregates and group-by as future work and should be updated when this merges.

@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
zero-docs Ready Ready Preview Nov 6, 2026 11:25am UTC

Request Review

@arv
arv marked this pull request as ready for review November 12, 2026 11:13
Copilot AI lite review requested due to automatic review settings November 12, 2026 11:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An active documentation issue remains because the restriction around chaining distinct() and count() is ambiguous and contradicts nearby guidance.

1 open issue
What changed in this PR

Documents ZQL aggregate, distinct(), and groupBy() query capabilities, along with regenerated search metadata.

Changes:

  • Adds aggregate documentation for queries and relationships, including result semantics, synchronization, supported types, and mutation timing.
  • Documents distinct() and groupBy() behavior, examples, limitations, null handling, ordering, and update behavior.
  • Regenerates the search index with the new sections and updated identifiers.
File Description
contents/​docs/​zql.mdx Adds documentation for ZQL aggregates, distinct(), and groupBy(), including examples, semantics, limitations, and synchronization behavior.
assets/​search-index.json Indexes the new ZQL documentation sections and updates subsequent section identifiers.

Review effort: Lite

Comment thread contents/docs/zql.mdx

The aggregates work as they do without `groupBy()`, and a group whose values are all `null` gets `null` from `sum()`, `avg()`, `min()`, and `max()`. As with `distinct()`, rows with a `null` value form a group of their own, and the rows can only be ordered by the grouped columns. Ordering groups by their aggregate, such as the creators with the most issues first, isn't supported yet.

Neither `distinct()` nor `groupBy()` can be combined with `limit()`, `start()`, `one()`, `related()`, or another aggregate yet, and neither can group by a JSON column. They can't be used inside `related()` or `whereExists()` either, so counting each issue's distinct commenters isn't possible yet. As with other aggregates, a query defined with `defineQuery()` has to include them in its definition.

This branch was successfully deployed

1 active deployment
Preview — 1dd743e3 Deployed Nov 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants