You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(db): support aggregates nested inside expressions (#720) (#1274)
* test(db, react-db): reproduce aggregates nested inside expressions
Add failing tests that reproduce the issue where aggregates wrapped
inside other expressions (e.g. coalesce(count(...), 0)) throw
QueryCompilationError: Unknown expression type: agg.
Tests cover coalesce wrapping count/sum, add combining two aggregates,
mixed plain and wrapped aggregates, and subquery join sources — in both
@tanstack/db and useLiveQuery.
Ref: #720
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* ci: apply automated fixes
* fix(db): support aggregates nested inside expressions
Extract nested aggregates (e.g. coalesce(count(...), 0)) into synthetic
aliases, register them with the groupBy operator, and evaluate the
wrapper expression post-aggregation. This follows the same pattern used
for HAVING clauses via replaceAggregatesByRefs.
Changes:
- select.ts: defer expressions containing nested aggregates to groupBy
- group-by.ts: extract, register, and evaluate wrapped aggregates in
both single-group and multi-group paths
- index.ts: detect nested aggregates for implicit single-group aggregation
Fixes: #720
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* ci: apply automated fixes
* chore: add changeset
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* ci: apply automated fixes
* fix(db): clean up synthetic __agg_ keys from result rows
Remove temporary __agg_N keys from finalResults after wrapped-aggregate
expressions have been evaluated. Without this cleanup, internal synthetic
aliases leak onto user-visible projected result rows.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* refactor(db): extract evaluateWrappedAggregates helper
Deduplicate the synthetic-value copy, evaluate, and cleanup logic that
was repeated in both the single-group and multi-group paths of
processGroupBy.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* test(db, react-db): assert exact result shape for nested aggregates
Use toEqual to verify that projected rows contain only the expected
keys and no leaked internal state like __agg_N synthetic aliases.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
0 commit comments