-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
from tests.integration_tests.test_app import app | ||
|
||
from .base_tests import SupersetTestCase | ||
from .conftest import only_postgresql | ||
|
||
VIRTUAL_TABLE_INT_TYPES: Dict[str, Pattern[str]] = { | ||
"hive": re.compile(r"^INT_TYPE$"), | ||
|
@@ -659,51 +660,90 @@ def test_filter_on_text_column(text_column_table): | |
assert result_object.df["count"][0] == 1 | ||
|
||
|
||
def test_should_generate_closed_and_open_time_filter_range(): | ||
with app.app_context(): | ||
if backend() != "postgresql": | ||
pytest.skip(f"{backend()} has different dialect for datetime column") | ||
|
||
table = SqlaTable( | ||
table_name="temporal_column_table", | ||
sql=( | ||
"SELECT '2021-12-31'::timestamp as datetime_col " | ||
"UNION SELECT '2022-01-01'::timestamp " | ||
"UNION SELECT '2022-03-10'::timestamp " | ||
"UNION SELECT '2023-01-01'::timestamp " | ||
"UNION SELECT '2023-03-10'::timestamp " | ||
), | ||
database=get_example_database(), | ||
) | ||
TableColumn( | ||
column_name="datetime_col", | ||
type="TIMESTAMP", | ||
table=table, | ||
is_dttm=True, | ||
) | ||
SqlMetric(metric_name="count", expression="count(*)", table=table) | ||
result_object = table.query( | ||
@only_postgresql | ||
def test_should_generate_closed_and_open_time_filter_range(login_as_admin): | ||
table = SqlaTable( | ||
table_name="temporal_column_table", | ||
sql=( | ||
"SELECT '2021-12-31'::timestamp as datetime_col " | ||
"UNION SELECT '2022-01-01'::timestamp " | ||
"UNION SELECT '2022-03-10'::timestamp " | ||
"UNION SELECT '2023-01-01'::timestamp " | ||
"UNION SELECT '2023-03-10'::timestamp " | ||
), | ||
database=get_example_database(), | ||
) | ||
TableColumn( | ||
column_name="datetime_col", | ||
type="TIMESTAMP", | ||
table=table, | ||
is_dttm=True, | ||
) | ||
SqlMetric(metric_name="count", expression="count(*)", table=table) | ||
result_object = table.query( | ||
{ | ||
"metrics": ["count"], | ||
"is_timeseries": False, | ||
"filter": [], | ||
"from_dttm": datetime(2022, 1, 1), | ||
"to_dttm": datetime(2023, 1, 1), | ||
"granularity": "datetime_col", | ||
} | ||
) | ||
""" >>> result_object.query | ||
SELECT count(*) AS count | ||
FROM | ||
(SELECT '2021-12-31'::timestamp as datetime_col | ||
UNION SELECT '2022-01-01'::timestamp | ||
UNION SELECT '2022-03-10'::timestamp | ||
UNION SELECT '2023-01-01'::timestamp | ||
UNION SELECT '2023-03-10'::timestamp) AS virtual_table | ||
WHERE datetime_col >= TO_TIMESTAMP('2022-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') | ||
AND datetime_col < TO_TIMESTAMP('2023-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') | ||
""" | ||
assert result_object.df.iloc[0]["count"] == 2 | ||
|
||
|
||
def test_none_operand_in_filter(login_as_admin, physical_dataset): | ||
expected_results = [ | ||
Comment on lines
+707
to
+708
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case is the new one. |
||
{ | ||
"operator": FilterOperator.EQUALS.value, | ||
"count": 10, | ||
"sql_should_contain": "COL4 IS NULL", | ||
}, | ||
{ | ||
"operator": FilterOperator.NOT_EQUALS.value, | ||
"count": 0, | ||
"sql_should_contain": "COL4 IS NOT NULL", | ||
}, | ||
] | ||
for expected in expected_results: | ||
result = physical_dataset.query( | ||
{ | ||
"metrics": ["count"], | ||
"filter": [{"col": "col4", "val": None, "op": expected["operator"]}], | ||
"is_timeseries": False, | ||
"filter": [], | ||
"from_dttm": datetime(2022, 1, 1), | ||
"to_dttm": datetime(2023, 1, 1), | ||
"granularity": "datetime_col", | ||
} | ||
) | ||
""" >>> result_object.query | ||
SELECT count(*) AS count | ||
FROM | ||
(SELECT '2021-12-31'::timestamp as datetime_col | ||
UNION SELECT '2022-01-01'::timestamp | ||
UNION SELECT '2022-03-10'::timestamp | ||
UNION SELECT '2023-01-01'::timestamp | ||
UNION SELECT '2023-03-10'::timestamp) AS virtual_table | ||
WHERE datetime_col >= TO_TIMESTAMP('2022-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') | ||
AND datetime_col < TO_TIMESTAMP('2023-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US') | ||
""" | ||
assert result_object.df.iloc[0]["count"] == 2 | ||
assert result.df["count"][0] == expected["count"] | ||
assert expected["sql_should_contain"] in result.query.upper() | ||
|
||
with pytest.raises(QueryObjectValidationError): | ||
for flt in [ | ||
FilterOperator.GREATER_THAN, | ||
FilterOperator.LESS_THAN, | ||
FilterOperator.GREATER_THAN_OR_EQUALS, | ||
FilterOperator.LESS_THAN_OR_EQUALS, | ||
FilterOperator.LIKE, | ||
FilterOperator.ILIKE, | ||
]: | ||
physical_dataset.query( | ||
{ | ||
"metrics": ["count"], | ||
"filter": [{"col": "col4", "val": None, "op": flt.value}], | ||
"is_timeseries": False, | ||
} | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
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.
There was a problem hiding this comment.
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 uselogin_as_admin
to define the Flask app context, there's no logical change.