feat: add aggregate query support (GROUP BY + aggregate functions)#750
Merged
Conversation
- Add AggregateIrExpression type and AggregateIrItem to new-kid-interpreter.ts
- Add AggregateExpression, AggregateMap, agg namespace, aggregate DSL function to dsl.ts
- Extend FilterArgs.select with { key, path } (aliased field) and { key, aggregate } types
- Implement GROUP BY + aggregate in Memory store (memFilter)
- Implement GROUP BY + aggregate in SQL store (buildWhereSQLQuery)
- Implement GROUP BY + SUM(IIF) for Cosmos DB (buildWhereCosmosQuery3)
- Handle mode === "aggregate" in Repository.query (bypass id/_etag augmentation)
- Add tests for sql-store, cosmos-query, and query (memFilter) test suites
Agent-Logs-Url: https://github.com/effect-app/libs/sessions/4a46d705-8acf-4e09-b756-77ff419dca70
Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
Agent-Logs-Url: https://github.com/effect-app/libs/sessions/4a46d705-8acf-4e09-b756-77ff419dca70 Co-authored-by: patroza <42661+patroza@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
patroza
May 13, 2026 10:02
View session
Member
|
@copilot Is there some overlap now between especially agregrate and projectComputed? |
Contributor
Author
There is some conceptual overlap (both compute values in the query layer), but they solve different shapes: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
Q.aggregate(schema, aggregateMap)— a new query operator that performs GROUP BY + aggregate functions at the database level (Memory, SQL, Cosmos) instead of fetching all rows and grouping in memory.Motivation
Replaces patterns like:
With a single DB-level aggregate query:
New API
aggDSL namespace:agg.field(path)— group-by field reference (doc path → output alias)agg.count()— COUNT(*)agg.countWhen(operation)— COUNT of rows matching filteragg.sum(field)— SUM of a numeric fieldagg.min(field)/agg.max(field)— MIN/MAX of a fieldaggregate(schema, aggregateMap)— query operator using the aboveChanges
src/Model/query/new-kid-interpreter.tsAggregateIrExpressiontype,AggregateIrItem, extendResult, handle"aggregate"modesrc/Model/query/dsl.tsAggregateExpression,AggregateMap,aggconst,aggregate()functionsrc/Store/service.tsFilterArgs.selectwith{ key, path }and{ key, aggregate }item typessrc/Store/Memory.tsmemFiltersrc/Store/SQL/query.tsGROUP BY+COUNT(CASE WHEN ...)/SUM/MIN/MAXsrc/Store/Cosmos/query.tsGROUP BY+SUM(IIF(...))for conditional countssrc/Model/Repository/internal/internal.ts"aggregate"mode dispatch — bypass id/_etag augmentation, decode raw rowstest/sql-store.test.tstest/cosmos-query.test.tstest/query.test.tsmemFilteraggregate unit tests