Skip to content

test: aggregate filters through a to-many relationship count each record once - #7

Draft
wtsnz wants to merge 1 commit into
mainfrom
fix/filter-fanout-tests
Draft

wtsnz wants to merge 1 commit into
mainfrom
fix/filter-fanout-tests

Conversation

@wtsnz

@wtsnz wtsnz commented Sep 26, 2026

Copy link
Copy Markdown
Owner

Regression tests for aggregates that count a record once per matching related row when their filter references a to-many relationship. The fix is in AshSQL: wtsnz/ash_sql#12.

What they check

A post has three comments:

  • two with 2 likes, which match ratings.score > 5 (the first through two ratings, the second through one);
  • one with 7 likes and a single low rating.

The tests check that:

  • count, sum of likes and list of likes through ratings.score > 5 return 2, 4 and [2, 2];
  • ratings.score > 8 and ratings.score < 10 only matches the first comment, since both conditions must hold for the same rating;
  • ratings.score > 7 or likes == 7 sums to 11, counting each comment once.

Results

  • With the published AshSQL: they fail. The count is 3 and the or sum is 13.
  • With the AshSQL fix (ASH_SQL_VERSION=local): they pass. The full suite fails the same 39 tests as main in the local test database, and nothing new.

This PR depends on that AshSQL fix being released.

Found by

The data-layer conformance suite (wtsnz/ash#7), gap filter-fanout.

…ord once

An aggregate filtered through a to-many relationship must aggregate each
matching record once, however many of its related rows match, and
conditions on one relationship must hold for the same related row. The
lateral strategy currently counts a record once per matching related
row; these tests pass with the AshSQL fix (ASH_SQL_VERSION=local).
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