Skip to content

test(semantic-layer): cover grouped exclusion filters in conformance kit - #46549

Merged
mikebridge merged 2 commits into
apache:masterfrom
mikebridge:conformance-or-groups
Nov 26, 2026
Merged

mikebridge merged 2 commits into
apache:masterfrom
mikebridge:conformance-or-groups

Conversation

@mikebridge

Copy link
Copy Markdown
Member

SUMMARY

TL;DR: Extend the provider conformance tests and browser-test stub to exercise grouped exclusion filters, including NULL rows.

Background: Semantic-view user exclusions reach providers as a negated comparison OR IS_NULL, combined with any other filters using AND. This preserves unselected NULL rows, as described in #46377.

Problem: The kit's SQLite example rejected a non-empty NOT IN, and the browser-test stub rejected every OR group. Those test adapters could not exercise the exclusion shapes the host already sends.

What this changes:

  • Add four required conformance cases: or_not_in, or_not_equals, or_not_like, and or_not_ilike.
  • Support those shapes in the test adapters while keeping bare negated predicates' NULL semantics separate from the normalized OR group.
  • Validate all stub predicates before evaluating rows, so a matching sibling cannot hide an unsupported filter.
  • Strengthen the example data and mutation tests to catch dropped NULL branches, parentheses, outer comparisons, and entire groups.
  • Document the four new fixture entries and case-list updates that downstream test suites need when upgrading the kit.

This changes testing utilities and fixtures, not production query translation or provider capabilities.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable; no UI change.

TESTING INSTRUCTIONS

From the repository root with the development environment active:

PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTHONPATH=$PWD/superset-core/src python -m pytest -p superset_core.semantic_layers.testing -q -o addopts='' superset-core/tests/semantic_layers/test_conformance.py
PYTHONPATH=.:superset-core/src python -m pytest tests/unit_tests/semantic_layers/e2e_stub_extension_test.py -q

Observed before the adapter changes: four SDK exclusion cases and nine stub/host cases failed. Afterward: 156 kit tests passed with four existing capability-related skips, and all 34 stub/host tests passed. The example's reusable conformance suite has 34 cases: 30 pass and four skip. All changed-file hooks pass, including MyPy, Ruff and Pylint.

Expected answers come from the raw test rows. Mutation tests confirm the exclusion fixtures detect lost parentheses and predicates in both top-level filter orders. Host tests use the actual chart-data endpoint and mapper with the test extension. No live warehouse or browser certification is claimed.

ADDITIONAL INFORMATION

  • Has associated issue: follow-up test coverage for fix(semantic-layer): keep NULL rows in user exclusion filters #46377
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Provider test suites inheriting SemanticProviderConformance need the four added semantic_query_cases entries; this is called out in UPDATING.md and the provider testing guide.

Exercise the normalized exclusions already emitted by the host. Teach the test-only SQLite adapter and E2E stub to retain NULL rows through explicit OR groups while respecting outer predicates, and add four required conformance witnesses.

Use independently calculated fixture results and mutation checks for lost grouping, NULL branches and comparisons. Document the new fixture entries required by downstream kit consumers.
@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Nov 25, 2026
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.02%. Comparing base (2911058) to head (992da49).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #46549       +/-   ##
===========================================
+ Coverage   56.67%   86.02%   +29.35%     
===========================================
  Files        3130     3135        +5     
  Lines      217962   218676      +714     
  Branches    51682    51706       +24     
===========================================
+ Hits       123528   188126    +64598     
+ Misses      93238    27129    -66109     
- Partials     1196     3421     +2225     
Flag Coverage Δ
hive 33.79% <ø> (-0.02%) ⬇️
mysql 51.59% <ø> (?)
postgres 51.62% <ø> (?)
presto 35.49% <ø> (-0.02%) ⬇️
python 88.51% <ø> (+52.93%) ⬆️
sqlite 51.29% <ø> (?)
superset-extensions-cli 91.26% <ø> (?)
unit 84.05% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 992da49fa7b7

@rebenitez1802 rebenitez1802 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve: a solid test-only PR. The expected answers match real engines (SQLite, DuckDB and Postgres all agree on the four cases), and the fixtures match the shape _normalize_user_filter sends from #46377. Nothing blocks merge.

🟡 Medium — or_not_ilike is required, with no way for a provider to opt out
superset/semantic_layers/mapper.py:121-123 says that, with no capability flag, a provider that cannot express ILIKE may raise an error. The kit, however, makes NOT ILIKE mandatory: there is no skip path like the one grain has, and no fixture for an expected rejection. Is that intended? Positive LIKE/ILIKE aren't required at all.

🟢 Low — Missing fixture entry fails with a bare KeyError
A downstream suite that has only the 6 old cases fails with KeyError: 'or_not_in' at testing.py:189 (outside the diff). Fix: add assert case in semantic_query_cases, f"semantic_query_cases must provide {case!r}; see the provider testing guide" before the lookup.

🟢 Low — The stub can't group by a dimension that has NULLs
Now that NULL rows survive exclusions, the stub's get_table and get_values sorts raise TypeError when a NULL is compared with a string, and the chart-data call returns a 500. The sort code predates this PR, and the shipped ROWS contain no NULLs, so it isn't reachable today. It does mean test_exclusion_through_host_mapper passes whether or not the IS NULL branch is there. Fix: sort with the key (value is None, value), and add a NULL row to that test.

Heads-up: this has small conflicts with drafts #46281 and #46283, in the docs case-list sentence and in the stub's _matches (Dimension → DimensionSelection). Whichever lands second needs a mechanical fix.

Comment on lines +306 to +309
def test_invalid_or_leaf_is_validated_before_matching(
stub_view: SemanticViewABC,
) -> None:
"""A matching OR sibling must not hide an unsupported operator."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 This test relies on frozenset iteration order. If the stub regressed to checking leaves lazily inside _matches, the test would still pass on about half of PYTHONHASHSEED values: when the empty NOT IN leaf comes first, any() short-circuits and the LIKE leaf is never checked. Making any row match fail the test removes that dependency. I checked it against that mutation on 10 seeds: the current test missed it on 5, the patched test caught it on all 4 seeds I re-ran from those 5, and the patched test passes 34/34 against the PR's code on all 10 seeds.

Suggested change
def test_invalid_or_leaf_is_validated_before_matching(
stub_view: SemanticViewABC,
) -> None:
"""A matching OR sibling must not hide an unsupported operator."""
def test_invalid_or_leaf_is_validated_before_matching(
stub_view: SemanticViewABC,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""A matching OR sibling must not hide an unsupported operator."""
monkeypatch.setattr(
sys.modules[type(stub_view).__module__],
"_matches",
lambda row, leaf: pytest.fail("a row was matched before validation"),
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch—adopted in 992da49. Moving validation into row matching escaped the old test on seeds 1 and 2; the revised test catches it on all four seeds checked (1–4), and the restored stub passes all 34 tests on each seed.

groups: list[OrFilter] = [
item for item in query.filters or set() if isinstance(item, OrFilter)
]
assert len(groups) == 1, "or fixture requires one normalized IN/NULL group"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 nit: for the new exclusion cases this message still says IN/NULL, but the group is NOT IN/!=/NOT LIKE/NOT ILIKE.

Suggested change
assert len(groups) == 1, "or fixture requires one normalized IN/NULL group"
assert len(groups) == 1, (
f"or fixture requires one normalized {operator.value}/NULL group"
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks—adopted in 992da49; the diagnostic now names the expected operator, including the exclusion cases.

Fail if any row is matched before invalid OR leaves are rejected, independent of frozenset iteration order. Name the expected comparison operator in conformance witness diagnostics.
@mikebridge
mikebridge merged commit 2ddee28 into apache:master Nov 26, 2026
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Namespace | Anything related to documentation size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants