Repository navigation
test(semantic-layer): cover grouped exclusion filters in conformance kit - #46549
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rebenitez1802
left a comment
There was a problem hiding this comment.
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.
| def test_invalid_or_leaf_is_validated_before_matching( | ||
| stub_view: SemanticViewABC, | ||
| ) -> None: | ||
| """A matching OR sibling must not hide an unsupported operator.""" |
There was a problem hiding this comment.
🟡 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.
| 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"), | |
| ) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
🟢 nit: for the new exclusion cases this message still says IN/NULL, but the group is NOT IN/!=/NOT LIKE/NOT ILIKE.
| 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" | |
| ) |
There was a problem hiding this comment.
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.
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:
or_not_in,or_not_equals,or_not_like, andor_not_ilike.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:
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
Provider test suites inheriting
SemanticProviderConformanceneed the four addedsemantic_query_casesentries; this is called out inUPDATING.mdand the provider testing guide.