Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ assists people when migrating to a new version.

## Next

- Provider tests inheriting `SemanticProviderConformance` must supply four
additional `semantic_query_cases`: `or_not_in`, `or_not_equals`, `or_not_like`,
and `or_not_ilike`. These check the existing normalized exclusion-filter
contract, including NULL retention and outer AND predicates. Update any
explicit conformance-case allowlist when adopting the kit; see the
[provider testing guide](docs/developer_docs/semantic-layer-provider-testing.md).

- Dashboard history records related chart archives using the new
`version_chart_archive_scope` table. Run `superset db upgrade` before deploying
new archive writes with versioning capture enabled. During a rollout, activity
Expand Down
21 changes: 19 additions & 2 deletions docs/developer_docs/semantic-layer-provider-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ separate integration tests.
| `semantic_change_catalog` | No-argument callable changing the controlled source catalog: add a visible member on every call, without clearing provider caches. |
| `semantic_provider_class` | `(importable_module_name, class_name)` of the layer for an isolated import and static-schema check. Dependencies must already be installed. |

Required query cases are `identity`, `grain`, `null`, `not_null`, `or`, and
`order_limit`. Use member names distinct from private IDs and display labels.
Required query cases are `identity`, `grain`, `null`, `not_null`, `or`,
`or_not_in`, `or_not_equals`, `or_not_like`, `or_not_ilike`, and `order_limit`.
Use member names distinct from private IDs and display labels.
For `grain`, use a grain-bearing dimension with data whose aggregation distinguishes the selected grain from raw values. Multiple grain variants for one name are allowed, not required. When the catalog declares no grain-bearing dimension, the case skips with an explicit reason before looking up its fixture entry; such providers may omit the `grain` entry. This reports unexercised grain coverage, not a passing grain check.
NULL and grouped-OR fixtures must select NULL and non-NULL branches observably;
the `or` case must use the host-normalized shape: one `OrFilter` containing
Expand All @@ -74,6 +75,22 @@ The SQLite example uses a February lower bound, with A and NULL rows on both sid
of that bound: the correct totals are NULL=1, A=5, B=8. This distinguishes either
ordering of the outer AND and the OR group. A February C row with amount 6 must
be excluded; dropping the OR group incorrectly adds C=6 to the result.
The four exclusion cases use the same grouped shape, replacing `IN` with
`NOT IN`, `!=`, `NOT LIKE`, or `NOT ILIKE`, respectively. The `NOT IN` operand
must contain at least two non-NULL values; pattern operands must contain a
wildcard. Keep an outer AND comparison and group by the filtered dimension,
with both NULL and non-NULL groups in the expected result. Seed rows on both
sides of the outer comparison and rows excluded by the negated leaf, so dropping
the NULL branch, the group, its parentheses or the outer predicate changes the
answer. A plain non-empty negated leaf still excludes NULL: it is the explicit
`IS_NULL` branch that retains NULL rows in a user exclusion.
The SQLite example expects NULL=1 and C=6 for `NOT IN {A, B}`; NULL=1, C=6,
B=8 for `!= A`; and NULL=1, A=5, C=6 for `NOT LIKE 'B%'` and `NOT ILIKE 'b%'`.
These are required conformance cases, not optional advertised capabilities.
The example also has a January C row, so a lost pair of parentheses is observable
whether the outer AND predicate appears before or after the OR group.
Consumers upgrading the kit must provide the four fixture entries and review
the new case IDs in any explicit case allowlist before certifying providers.
Seed more result rows than the limit, in an order that differs from the requested
sort. The suite compares exact Arrow column names, types, values and row order,
without prescribing column order or field nullability.
Expand Down
76 changes: 62 additions & 14 deletions superset-core/src/superset_core/semantic_layers/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,19 @@ def test_catalog_identity(
), "preferred_temporal_dimension must remain stable on equivalent reload"

@pytest.mark.parametrize(
"case", ["identity", "grain", "null", "not_null", "or", "order_limit"]
"case",
[
"identity",
"grain",
"null",
"not_null",
"or",
"or_not_in",
"or_not_equals",
"or_not_like",
"or_not_ilike",
"order_limit",
],
)
def test_query_outputs(
self,
Expand Down Expand Up @@ -195,6 +207,25 @@ def test_query_outputs(
)
elif case == "or":
_assert_normalized_or_witness(query)
elif case in {"or_not_in", "or_not_equals", "or_not_like", "or_not_ilike"}:
exclusion: Operator = {
"or_not_in": Operator.NOT_IN,
"or_not_equals": Operator.NOT_EQUALS,
"or_not_like": Operator.NOT_LIKE,
"or_not_ilike": Operator.NOT_ILIKE,
}[case]
_assert_normalized_or_witness(query, exclusion)
group: OrFilter = next(
item for item in query.filters or set() if isinstance(item, OrFilter)
)
member: Dimension | Metric | None = next(iter(group.filters)).column
assert member is not None, "exclusion fixture requires a member"
assert member in query.dimensions, (
"exclusion fixture must group by the filtered dimension"
)
assert 0 < expected.column(member.name).null_count < expected.num_rows, (
"exclusion fixture must retain NULL and non-NULL groups"
)
elif case == "order_limit":
assert query.order
assert query.limit is not None
Expand Down Expand Up @@ -437,34 +468,51 @@ def test_imports_and_static_schema(
)


def _assert_normalized_or_witness(query: SemanticQuery) -> None:
"""Require the host's mixed-IN/NULL group and an outer comparison."""
def _assert_normalized_or_witness(
query: SemanticQuery, operator: Operator = Operator.IN
) -> None:
"""Require a normalized comparison/NULL group and an outer comparison."""
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.

group: OrFilter = groups[0]
membership: list[Filter] = [
leaf for leaf in group.filters if leaf.operator == Operator.IN
leaf for leaf in group.filters if leaf.operator == operator
]
nulls: list[Filter] = [
leaf for leaf in group.filters if leaf.operator == Operator.IS_NULL
]
assert len(group.filters) == 2, "or fixture requires IN and IS_NULL leaves"
assert len(membership) == 1, "or fixture requires IN and IS_NULL leaves"
assert len(nulls) == 1, "or fixture requires IN and IS_NULL leaves"
message: str = f"or fixture requires {operator.value} and IS_NULL leaves"
assert len(group.filters) == 2, message
assert len(membership) == 1, message
assert len(nulls) == 1, message
selected: Filter = membership[0]
assert selected.column is not None, "or fixture leaves must select the same member"
assert selected.column == nulls[0].column, (
"or fixture leaves must select the same member"
)
assert isinstance(selected.value, frozenset), "or fixture IN requires a frozenset"
assert len(selected.value) >= 2, (
"or fixture IN requires at least two non-NULL values"
)
assert None not in selected.value, (
"or fixture IN requires at least two non-NULL values"
)
if operator in {Operator.IN, Operator.NOT_IN}:
assert isinstance(selected.value, frozenset), (
"or fixture membership requires a frozenset"
)
assert len(selected.value) >= 2, (
"or fixture membership requires at least two non-NULL values"
)
assert None not in selected.value, (
"or fixture membership requires at least two non-NULL values"
)
else:
assert selected.value is not None, (
"or fixture comparison requires a non-NULL value"
)
if operator in {Operator.NOT_LIKE, Operator.NOT_ILIKE}:
assert isinstance(selected.value, str), (
"or fixture pattern requires a string"
)
assert any(char in selected.value for char in "%_"), (
"or fixture pattern requires a wildcard"
)
assert any(
isinstance(item, Filter)
and item.type == selected.type
Expand Down
24 changes: 21 additions & 3 deletions superset-core/tests/semantic_layers/conformance_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def execute(self, sql: str, parameters: list[object]) -> list[tuple[Any, ...]]:
raise ConnectionError("test backend unavailable")
connection: sqlite3.Connection
with closing(sqlite3.connect(":memory:")) as connection:
connection.execute("PRAGMA case_sensitive_like = ON")
connection.execute(
"CREATE TABLE records(category TEXT, occurred TEXT, amount INT)"
)
Expand All @@ -68,6 +69,7 @@ def execute(self, sql: str, parameters: list[object]) -> list[tuple[Any, ...]]:
[
("B", "2026-02-04", 8),
("C", "2026-02-07", 6),
("C", "2026-01-04", 4),
(None, "2026-01-03", 3),
(None, "2026-02-06", 1),
("A", "2026-02-05", 5),
Expand Down Expand Up @@ -213,6 +215,11 @@ def _predicate(expression: FilterExpression, parameters: list[object]) -> str:
raise SemanticQueryRejectedError(SemanticQueryErrorCode.INVALID_FILTER)
if expression.column is None or expression.column.name != "category":
raise SemanticQueryRejectedError(SemanticQueryErrorCode.INVALID_FILTER)
return _category_predicate(expression, parameters)


def _category_predicate(expression: Filter, parameters: list[object]) -> str:
"""Render category predicates with SQL NULL semantics and bound operands."""
if expression.operator == Operator.IS_NULL:
return "category IS NULL"
if expression.operator == Operator.IS_NOT_NULL:
Expand All @@ -222,11 +229,20 @@ def _predicate(expression: FilterExpression, parameters: list[object]) -> str:
if expression.operator == Operator.EQUALS and expression.value is not None:
parameters.append(expression.value)
return "category = ?"
if expression.operator in {
Operator.NOT_EQUALS,
Operator.NOT_LIKE,
Operator.NOT_ILIKE,
} and isinstance(expression.value, str):
parameters.append(expression.value)
if expression.operator == Operator.NOT_ILIKE:
return "LOWER(category) NOT LIKE LOWER(?)"
return f"category {expression.operator.value} ?"
raise SemanticQueryRejectedError(SemanticQueryErrorCode.INVALID_FILTER)


def _membership(expression: Filter, parameters: list[object]) -> str:
"""Render IN values; empty IN is FALSE and empty NOT IN is TRUE."""
"""Render bound membership values, including empty-set constants."""
if not isinstance(expression.value, frozenset):
raise SemanticQueryRejectedError(SemanticQueryErrorCode.INVALID_FILTER)
if not expression.value:
Expand All @@ -235,10 +251,12 @@ def _membership(expression: Filter, parameters: list[object]) -> str:
values: list[str] = sorted(
value for value in expression.value if isinstance(value, str)
)
if expression.operator != Operator.IN or len(values) != len(expression.value):
if len(values) != len(expression.value):
raise SemanticQueryRejectedError(SemanticQueryErrorCode.INVALID_FILTER)
parameters.extend(values)
return "category IN (" + ", ".join("?" for _ in expression.value) + ")"
return (
f"category {expression.operator.value} (" + ", ".join("?" for _ in values) + ")"
)


def _result(
Expand Down
Loading
Loading