Repository navigation
fix(semantic-layers): give empty IN/NOT IN filters SQL semantics - #45904
Draft
mikebridge wants to merge 1 commit into
Draft
mikebridge wants to merge 1 commit into
mikebridge wants to merge 1 commit into
Conversation
An empty IN selection is a FALSE predicate and an empty NOT IN is TRUE, NULL rows included, applied where the filter sits. The host passes the empty set to providers instead of rejecting the query, the cache mask keeps NULL rows for an empty NOT IN, and containment no longer treats an empty NOT IN as proof of IS NOT NULL. An ungrouped cached rollup over no matching rows now returns one aggregate row (COUNT 0), as SQL does. The provider conformance kit derives empty IN/NOT IN witnesses from the identity and OR fixtures, including an empty leaf inside an OR group. UPDATING and the user, extension and provider-testing docs describe the new behavior.
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
TL;DR: A semantic-view chart filtered with an empty IN or NOT IN selection now returns a result, where it previously failed with "Semantic IN/NOT IN filters cannot be empty."
Background. These are the semantics of filtering by an empty set: membership in an empty set is FALSE, so an empty IN is FALSE and an empty NOT IN is TRUE, even when the value is NULL. The predicate applies where the filter sits, before aggregation, so an ungrouped
SELECT COUNT(*) ... WHERE FALSEreturns one row containing 0. This is about the empty-set predicate, not the literalIN ()syntax: many SQL dialects reject an empty list, so providers must render a constant or an equivalent native predicate instead.Dataset charts behave differently: they still reject an empty selection ("Filter value list cannot be empty"). This PR does not change dataset charts.
Problem.
Changes.
Operatordocstring defines the semantics and tells providers to render a constant or an equivalent predicate, never an empty SQL list.test_empty_membership, derived from each provider's existingidentityfixture, so providers add no fixtures. It checks:orfixture's OR group, an extra empty IN leaf leaves the result unchanged and an extra empty NOT IN leaf makes the group match every row.UPDATING.mdand the user, extension and provider-testing docs describe the new behavior; they previously said empty selections were rejected.IN (), so provider renderer tests should pin dialect-valid output.Nonempty membership, including the existing NULL handling, is unchanged.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable. Before: the chart-data request fails with "Semantic IN/NOT IN filters cannot be empty." After: the chart returns the SQL result described above.
TESTING INSTRUCTIONS
pytest tests/unit_tests/semantic_layers/null_filters_test.py tests/unit_tests/semantic_layers/cache_policy_test.pypytest superset-core/tests/semantic_layers/test_conformance.pyINfilter whose value list is[]. Grouped by that dimension, it returns no rows; with only a COUNT metric, it returns one row of 0. Change the filter toNOT INwith[]: the result matches the unfiltered chart, NULL group included.ADDITIONAL INFORMATION
Provider authors: the SDK conformance kit now includes
test_empty_membershipandtest_empty_membership_in_or_group. They need no new fixture beyond anidentityresult with a NULL group, but a provider that renders an empty SQL list or drops the filter will need to render a constant or an equivalent predicate.