Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support None operand in EQUAL operator #21713

Merged
merged 2 commits into from Oct 6, 2022

Conversation

zhaoyongjie
Copy link
Member

@zhaoyongjie zhaoyongjie commented Oct 6, 2022

SUMMARY

This PR intends to support the None operand with Equal and Not-Equal operators in Filters in QueryObject. Currently, the In operator has supported None operand calculation, in order to align that the Equal and Not-Equal should support as well.

After the PR, there are 4 approaches to generate is null or is not null filter in SQL.

  1. EQUAL / NOT EQUAL operator
>>> result = mock_dataset.query({
    "metrics": ["count"],
    "filter": [{"col": "col", "val": None, "op": "=="}],
    "is_timeseries": False,
})
>>> result.query
SELECT count(*) AS count
FROM mock_dataset
WHERE col IS NULL
  1. IS NULL / IS NOT NULL operator
>>> result = mock_dataset.query({
    "metrics": ["count"],
    "filter": [{"col": "col", "op": "IS NULL"}],
    "is_timeseries": False,
})
>>> result.query
SELECT count(*) AS count
FROM mock_dataset
WHERE col IS NULL
  1. IN operator
>>> result = mock_dataset.query({
    "metrics": ["count"],
    "filter": [{"col": "col", val: ["a", None], "op": "IN"}],
    "is_timeseries": False,
})
>>> result.query
SELECT count(*) AS count
FROM mock_dataset
WHERE col IS NULL
  OR col IN ('a')
  1. There is an additional case that <NULL> as filter operand literal constant in the EQ or IN operators
>>> result = mock_dataset.query({
    "metrics": ["count"],
    "filter": [{"col": "col", "val": '<NULL>', "op": "=="}],
    "is_timeseries": False,
})
>>> result.query
SELECT count(*) AS count
FROM mock_dataset
WHERE col IS NULL

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • 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

@codecov
Copy link

codecov bot commented Oct 6, 2022

Codecov Report

Merging #21713 (3614b05) into master (51c54b3) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #21713      +/-   ##
==========================================
- Coverage   66.84%   66.82%   -0.03%     
==========================================
  Files        1799     1799              
  Lines       68881    68881              
  Branches     7319     7319              
==========================================
- Hits        46044    46028      -16     
- Misses      20950    20966      +16     
  Partials     1887     1887              
Flag Coverage Δ
hive 52.91% <100.00%> (ø)
mysql 78.24% <100.00%> (+<0.01%) ⬆️
postgres 78.30% <100.00%> (+<0.01%) ⬆️
presto 52.81% <100.00%> (ø)
python 81.39% <100.00%> (-0.05%) ⬇️
sqlite ?
unit 50.95% <0.00%> (ø)

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

Impacted Files Coverage Δ
superset/charts/schemas.py 99.35% <ø> (ø)
superset/connectors/sqla/models.py 90.68% <100.00%> (+0.08%) ⬆️
superset/db_engine_specs/sqlite.py 89.28% <0.00%> (-7.15%) ⬇️
superset/utils/celery.py 86.20% <0.00%> (-3.45%) ⬇️
superset/connectors/sqla/utils.py 87.25% <0.00%> (-1.97%) ⬇️
superset/result_set.py 96.29% <0.00%> (-1.49%) ⬇️
superset/views/core.py 75.45% <0.00%> (-0.61%) ⬇️
superset/db_engine_specs/base.py 89.38% <0.00%> (-0.32%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pull-request-size pull-request-size bot added size/L and removed size/M labels Oct 6, 2022
Comment on lines -685 to +664
result_object = table.query(
@only_postgresql
def test_should_generate_closed_and_open_time_filter_range(login_as_admin):
Copy link
Member Author

Choose a reason for hiding this comment

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

bycatch: use only_postgresql decorator to narrow the test case, and use login_as_admin to define the Flask app context, there's no logical change.

Comment on lines +707 to +708
def test_none_operand_in_filter(login_as_admin, physical_dataset):
expected_results = [
Copy link
Member Author

Choose a reason for hiding this comment

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

This test case is the new one.

@zhaoyongjie zhaoyongjie requested a review from a team October 6, 2022 07:47
@zhaoyongjie zhaoyongjie changed the title feat: support None operand with equal operator feat: support None operand in Equal operator Oct 6, 2022
@zhaoyongjie zhaoyongjie changed the title feat: support None operand in Equal operator feat: support None operand in EQUAL operator Oct 6, 2022
Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

I hadn't noticed it actually allowed selecting the empty value despite the API not allowing it 😵‍💫 Works great! However, one bug that I noticed when testing + a few stylistic nits:

  1. When creating a new filter, then selecting "IS NOT NULL" operator and then switching back to "equals" or "not equals", the save button becomes disabled:
    image

  2. We should also update the pill labels to reflect that they are checking for NULL. For the "equals" case I'd do something like "col = NULL" and "col <> NULL":
    image
    image

  3. Also a bycatch, but I'd actually prefer for the NOT EQUALS operator to use the same ≠ character in the pill label that we're using in the dropdown:
    image

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

LGTM - leaving my comments on the table for a potential follow-up PR as they're mostly unrelated

@zhaoyongjie
Copy link
Member Author

@villebro Thanks a lot, I will fix the frontend problem in the separated PR.

@zhaoyongjie zhaoyongjie merged commit 05648eb into apache:master Oct 6, 2022
@john-bodley
Copy link
Member

@zhaoyongjie did you address the frontend issues that @villebro mentioned in a separate PR? If so could you reference this PR in said PR so there's a edge connecting the two PRs?

@zhaoyongjie
Copy link
Member Author

@john-bodley I will do these cases. thanks for the mention.

john-bodley added a commit to john-bodley/superset that referenced this pull request Nov 8, 2022
john-bodley added a commit to airbnb/superset-fork that referenced this pull request Nov 8, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants