dev#256
Merged
Merged
Conversation
improved documentation
Aggregate filters declared via `filter expr(...)` in the Ash DSL were
never applied — they were silently ignored by every code path in
run_aggregate_for_ids.
## Root cause
All three aggregate execution paths (Cypher push-down for plain fields,
Elixir-side for embedded JSON types, Elixir-side for expression
calculations) received `aggregate.filter` but never consulted it.
## Fix
Routing in run_aggregate_for_ids/5 is now:
1. Expression-calc field (Ash.Query.Calculation) → run_expr_agg, which
now applies the filter via apply_record_filter/3 before evaluating
the expression.
2. Any filter present on a plain or embedded aggregate →
run_filtered_aggregate/7 (new): loads full destination records via
related_nodes, applies Ash.Filter.Runtime.filter_matches/3 per-source
group, extracts field values, then reduces with apply_elixir_aggregate.
3. Embedded field (no filter) → run_embedded_agg (unchanged).
4. Plain field (no filter) → Cypher push-down (unchanged).
This keeps the fast Cypher path for the common unfiltered case while
fully honouring the data-layer contract for filtered aggregates.
## New helpers
- run_filtered_aggregate/7 — Elixir-side aggregate with runtime filter
- extract_aggregate_field_values/2 — extracts field from records, uniq?
- apply_record_filter/3 — applies Ash runtime filter to {id, record} pairs
## Tests
Added describe "filtered aggregates (#252)" covering: first, count,
exists (true and false), list, zero-record base case, and multi-post
correctness. Four filtered resource aggregates added to Post test fixture.
…ntly-dropped fix #252 aggregate filters silently dropped
…-fail-with-invalid-cypher-identifier-error backticks and fix for 252
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.
No description provided.