Skip to content

chore: add tests for ash_sql #243 - #811

Merged
zachdaniel merged 1 commit into
ash-project:mainfrom
matt-beanland:test/combination-part-order
Aug 3, 2026
Merged

chore: add tests for ash_sql #243#811
zachdaniel merged 1 commit into
ash-project:mainfrom
matt-beanland:test/combination-part-order

Conversation

@matt-beanland

@matt-beanland matt-beanland commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

Reproduction/regression test for: ash-project/ash_sql#244 (issue:
ash-project/ash_sql#243).

Ash.Query.combination_of/2 applies its parts in the order given, each to the result of
everything before it. ash_sql renders them as a flat chain of set operations, so SQL's own
precedence regroups a combination that spans more than one precedence level .
INTERSECTbinds tighter thanUNION/EXCEPT. The query then answers differently here than it does under Ash.DataLayer.Ets`.

The test adds a three-part case to test/combination_test.exs: base, union, then intersect,
where applying the parts in order and letting SQL regroup them give different answers. A fourth
record belongs to neither grouping, so reading the whole table cannot be mistaken for a pass.

against ash_sql 0.6.6      left:  ["alpha", "beta", "gamma"]
                           right: ["alpha", "gamma"]

with ash_sql#NNN           19 passed

Every existing combination test here stops at two parts, which is the one shape where the order
cannot be observed — two parts agree however they are grouped, and union/except share a
precedence in SQL so they agree too. That is why this has not surfaced.

⚠️ This test fails until ash_sql#244 lands and is released. Note also that main is currently red
independently of this: 11 tests in AshPostgres.AggregateReadActionTest fail on fc165f3e
against released ash_sql 0.6.6, unrelated to combinations or to this change.

Every existing combination test stops at two parts, which is the one shape
where the order cannot be observed: two parts agree however they are grouped,
and `union`/`except` share a precedence in SQL so they agree as well.

Add a three-part case spanning two precedence levels — base, union, then
intersect — where applying the parts in the order given and letting SQL's
precedence regroup them produce different answers. A fourth record belongs to
neither grouping, so reading the whole table cannot be mistaken for a pass.

Fails against ash_sql 0.6.6 and passes with ash-project/ash_sql#NNN, which
this reproduces.
@zachdaniel
zachdaniel merged commit 8d75c27 into ash-project:main Aug 3, 2026
@zachdaniel

Copy link
Copy Markdown
Contributor

🚀 Thank you for your contribution! 🚀

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