Skip to content

feat(zero-swift): aggregates, groupBy and JSON paths in the AST; JSON path filters - #68

Merged
tmm merged 1 commit into
mainfrom
swift-aggregates-ast
Nov 2, 2026
Merged

tmm merged 1 commit into
mainfrom
swift-aggregates-ast

Conversation

@tmm

@tmm tmm commented Nov 2, 2026

Copy link
Copy Markdown
Member

First of the stacked PRs that port upstream's aggregates, groupBy, distinct and JSON paths to the Swift client (plan).

  • AST: aggregate on a query and on a relationship, groupBy, and AST.ValuePosition.json. Decoding applies JS's wire checks (non-empty paths, integer indices from 0 to 2^31-1, path only with a field and not on count, distinct only on a fieldless count, JSON-path IN lists of one type). Strict decoding, normalization, the query hash (absent fields write nothing, so existing hashes are unchanged) and name mapping (a junction aggregate's field maps on the destination; a JSON path needs a json column) are all covered, plus Format.aggregate.
  • JSON path filters: $0.json(\.metadata, "tags", 0) == "bug" in the typed builder and eb.cmp(eb.json("metadata", "tags", 0), "bug") in the untyped one, with JS's type-strict predicate. Builder misuse JS throws for makes the query invalid, with JS's message.
  • Building a pipeline for an aggregate or a groupBy throws until the next PR adds the operators.

I folded the plan's second PR (JSON path filters) into this one, because the new .json value position needs its predicate anyway.

The vectors are generated from JS:

  • ast-features.json: strictASTSchema's verdict on 70 ASTs, plus normalizeAST, hashOfAST and mapAST (or its error) for the valid ones.
  • query-internals-hash.json: hashes of formats that carry aggregate.
  • ivm-features.json: 34 JSON-filter programs over datasets with varied user.metadata, including the builder's errors.

To check the vectors catch mistakes, I made the predicate return false instead of negated for a type mismatch; 12 cases then failed.

Breaking: AST.ValuePosition gains a case, so this has a minor changeset.

… path filters

The AST gets the query features of sync protocols 54-57: aggregate on a
query and on a relationship, groupBy, and JSON path references in
conditions, with JS's wire checks, normalization, hashes and name mapping,
and Format.aggregate. where() can compare a value inside a json column, in
the untyped builder (eb.json) and the typed one ($0.json(\.metadata, ...)),
type-strict as in JS. Building a pipeline for an aggregate or a groupBy
throws until the IVM operators land.

New vectors from JS: ast-features (strictASTSchema's verdict, normalizeAST,
hashOfAST and mapAST), query-internals-hash (Format.aggregate), and
ivm-features (JSON path filters over datasets with varied metadata,
including the builder's errors).

Amp-Thread-ID: https://ampcode.com/threads/T-01a19a37-5aa9-7256-bff5-cdc47c01a1fe
Co-authored-by: tmm <tmm@tmm.dev>
@tmm
tmm force-pushed the swift-aggregates-ast branch from 75edf80 to c733aa4 Compare November 2, 2026 20:32
@tmm
tmm merged commit 680af92 into main Nov 2, 2026
15 checks passed
@tmm
tmm deleted the swift-aggregates-ast branch November 2, 2026 23: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.

2 participants