Skip to content

feat(rds): agg aggregates, groupBy, having and not conditions - #353

Merged
bentsku merged 2 commits into
rds-select-joinsfrom
rds-aggregates
Nov 18, 2026
Merged

bentsku merged 2 commits into
rds-select-joinsfrom
rds-aggregates

Conversation

@bentsku

@bentsku bentsku commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #352.

Problem

@aws-appsync/utils/rds declares an agg helper, the groupBy and having select keys and a not condition group, none of which we provide: rds.agg is undefined, groupBy/having were dropped from the generated SQL without an error, and not was read as a column name.

Separately, an or item with several columns ORed every column: or: [{ a, b }, { c }] rendered (a) OR (b) OR (c), where AWS renders (a AND b) OR (c).

What this does

Behaviour recorded from EvaluateCode:

  • rds.agg: max, min, count, avg, sum and their *Distinct variants render MAX("a"), COUNT(DISTINCT "a"), etc. The column is validated when the helper is called: only COUNT takes *, a distinct aggregate never does, a nullish column renders an empty argument list, and a non-string column raises the ClassCastException AWS leaks, reproduced verbatim.
  • Aggregate columns: an aggregate is accepted as a column or as an alias value. returning refuses a bare aggregate but lets an aliased one through, and using accepts both, like AWS. An aggregate used as a statement, from source or bound value is rejected.
  • groupBy renders after WHERE: strings are quoted (a star too), 32-bit integers render as column positions, and an empty list is rejected.
  • having takes a sql template or a condition object, renders after GROUP BY (even without one) and before ORDER BY. Its condition object accepts aggregate conditions, { price: { sum: { gt: 100 } } } → SUM("price") > :P0, with eq/ne/gt/lt/ge/le only (AWS refuses between although the typings allow it) and a nullish value inlined as NULL. Aggregate conditions in WHERE or ON are rejected.
  • not groups render NOT (...) with their items ANDed, in WHERE, ON and HAVING. Unlike an empty and/or, an empty not still renders, as NOT ().
  • Group items are grouped as a whole, their columns ANDed, which fixes the or case above.
  • and/or/not are matched in any casing (OR, And), with messages naming the key as written. Operators and aggregate keys stay case-sensitive.

The WHERE builder becomes buildConditionParts(keyword, condition), shared by WHERE, ON and HAVING; it records which clause is rendering, which is how ON's string-only rule and the aggregate rules are applied.

The logical-group rendering is rewritten around that item grouping, dropping the grouping parameters buildWhereClause and buildWhereStatement threaded through.

Bumps to v0.1.11, with a changelog line covering #352 as well.

Tests

New __tests__/rds-aggregates.test.js, 92 cases recorded against AWS: each aggregate as a column and as a having condition, the argument validation, groupBy item types, clause ordering and validation order, and the aggregate rejections in WHERE, ON and returning.

New __tests__/rds-conditions.test.js, 38 cases recorded against AWS: not alone, nested and in each clause, its empty forms and validation, the logical key casing, and multi-column group items. The full suite passes.

🤖 Generated with Claude Code

Add the rds.agg helpers (max, min, count, avg, sum and their Distinct
variants), usable as select columns or aliased columns, and the groupBy
and having select clauses, with aggregate conditions accepted in having
only. Bumps to v0.1.11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bentsku
bentsku added this pull request to stack #354 November 18, 2026 16:50
Condition objects accept a `not` group, rendering `NOT (...)` with its
items ANDed, in WHERE, ON and HAVING. `and`/`or`/`not` are matched in any
casing, like AWS. A group item with several columns is now grouped as a
whole, so `or: [{ a, b }, { c }]` renders `(a AND b) OR (c)` instead of
ORing every column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bentsku bentsku changed the title feat(rds): agg aggregates, groupBy and having feat(rds): agg aggregates, groupBy, having and not conditions Nov 18, 2026
@bentsku
bentsku marked this pull request as ready for review November 18, 2026 16:58
@bentsku
bentsku merged commit 36cac62 into main Nov 18, 2026
4 checks passed
@bentsku
bentsku deleted the rds-aggregates branch November 18, 2026 16:59
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.

1 participant