Skip to content

Commit 32b1de1

Browse files
committed
Revert "feat: support None operand in EQUAL operator (apache#21713)"
This reverts commit 05648eb.
1 parent cd1b379 commit 32b1de1

File tree

3 files changed

+42
-90
lines changed

3 files changed

+42
-90
lines changed

superset/charts/schemas.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,7 @@ class ChartDataFilterSchema(Schema):
819819
)
820820
val = fields.Raw(
821821
description="The value or values to compare against. Can be a string, "
822-
"integer, decimal, None or list, depending on the operator.",
823-
allow_none=True,
822+
"integer, decimal or list, depending on the operator.",
824823
example=["China", "France", "Japan"],
825824
)
826825
grain = fields.String(

superset/connectors/sqla/models.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1629,14 +1629,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
16291629
elif op == utils.FilterOperator.IS_FALSE.value:
16301630
where_clause_and.append(sqla_col.is_(False))
16311631
else:
1632-
if (
1633-
op
1634-
not in {
1635-
utils.FilterOperator.EQUALS.value,
1636-
utils.FilterOperator.NOT_EQUALS.value,
1637-
}
1638-
and eq is None
1639-
):
1632+
if eq is None:
16401633
raise QueryObjectValidationError(
16411634
_(
16421635
"Must specify a value for filters "

tests/integration_tests/sqla_models_tests.py

+40-80
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
from tests.integration_tests.test_app import app
5050

5151
from .base_tests import SupersetTestCase
52-
from .conftest import only_postgresql
5352

5453
VIRTUAL_TABLE_INT_TYPES: Dict[str, Pattern[str]] = {
5554
"hive": re.compile(r"^INT_TYPE$"),
@@ -666,90 +665,51 @@ def test_filter_on_text_column(text_column_table):
666665
assert result_object.df["count"][0] == 1
667666

668667

669-
@only_postgresql
670-
def test_should_generate_closed_and_open_time_filter_range(login_as_admin):
671-
table = SqlaTable(
672-
table_name="temporal_column_table",
673-
sql=(
674-
"SELECT '2021-12-31'::timestamp as datetime_col "
675-
"UNION SELECT '2022-01-01'::timestamp "
676-
"UNION SELECT '2022-03-10'::timestamp "
677-
"UNION SELECT '2023-01-01'::timestamp "
678-
"UNION SELECT '2023-03-10'::timestamp "
679-
),
680-
database=get_example_database(),
681-
)
682-
TableColumn(
683-
column_name="datetime_col",
684-
type="TIMESTAMP",
685-
table=table,
686-
is_dttm=True,
687-
)
688-
SqlMetric(metric_name="count", expression="count(*)", table=table)
689-
result_object = table.query(
690-
{
691-
"metrics": ["count"],
692-
"is_timeseries": False,
693-
"filter": [],
694-
"from_dttm": datetime(2022, 1, 1),
695-
"to_dttm": datetime(2023, 1, 1),
696-
"granularity": "datetime_col",
697-
}
698-
)
699-
""" >>> result_object.query
700-
SELECT count(*) AS count
701-
FROM
702-
(SELECT '2021-12-31'::timestamp as datetime_col
703-
UNION SELECT '2022-01-01'::timestamp
704-
UNION SELECT '2022-03-10'::timestamp
705-
UNION SELECT '2023-01-01'::timestamp
706-
UNION SELECT '2023-03-10'::timestamp) AS virtual_table
707-
WHERE datetime_col >= TO_TIMESTAMP('2022-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')
708-
AND datetime_col < TO_TIMESTAMP('2023-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')
709-
"""
710-
assert result_object.df.iloc[0]["count"] == 2
711-
712-
713-
def test_none_operand_in_filter(login_as_admin, physical_dataset):
714-
expected_results = [
715-
{
716-
"operator": FilterOperator.EQUALS.value,
717-
"count": 10,
718-
"sql_should_contain": "COL4 IS NULL",
719-
},
720-
{
721-
"operator": FilterOperator.NOT_EQUALS.value,
722-
"count": 0,
723-
"sql_should_contain": "COL4 IS NOT NULL",
724-
},
725-
]
726-
for expected in expected_results:
727-
result = physical_dataset.query(
668+
def test_should_generate_closed_and_open_time_filter_range():
669+
with app.app_context():
670+
if backend() != "postgresql":
671+
pytest.skip(f"{backend()} has different dialect for datetime column")
672+
673+
table = SqlaTable(
674+
table_name="temporal_column_table",
675+
sql=(
676+
"SELECT '2021-12-31'::timestamp as datetime_col "
677+
"UNION SELECT '2022-01-01'::timestamp "
678+
"UNION SELECT '2022-03-10'::timestamp "
679+
"UNION SELECT '2023-01-01'::timestamp "
680+
"UNION SELECT '2023-03-10'::timestamp "
681+
),
682+
database=get_example_database(),
683+
)
684+
TableColumn(
685+
column_name="datetime_col",
686+
type="TIMESTAMP",
687+
table=table,
688+
is_dttm=True,
689+
)
690+
SqlMetric(metric_name="count", expression="count(*)", table=table)
691+
result_object = table.query(
728692
{
729693
"metrics": ["count"],
730-
"filter": [{"col": "col4", "val": None, "op": expected["operator"]}],
731694
"is_timeseries": False,
695+
"filter": [],
696+
"from_dttm": datetime(2022, 1, 1),
697+
"to_dttm": datetime(2023, 1, 1),
698+
"granularity": "datetime_col",
732699
}
733700
)
734-
assert result.df["count"][0] == expected["count"]
735-
assert expected["sql_should_contain"] in result.query.upper()
736-
737-
with pytest.raises(QueryObjectValidationError):
738-
for flt in [
739-
FilterOperator.GREATER_THAN,
740-
FilterOperator.LESS_THAN,
741-
FilterOperator.GREATER_THAN_OR_EQUALS,
742-
FilterOperator.LESS_THAN_OR_EQUALS,
743-
FilterOperator.LIKE,
744-
FilterOperator.ILIKE,
745-
]:
746-
physical_dataset.query(
747-
{
748-
"metrics": ["count"],
749-
"filter": [{"col": "col4", "val": None, "op": flt.value}],
750-
"is_timeseries": False,
751-
}
752-
)
701+
""" >>> result_object.query
702+
SELECT count(*) AS count
703+
FROM
704+
(SELECT '2021-12-31'::timestamp as datetime_col
705+
UNION SELECT '2022-01-01'::timestamp
706+
UNION SELECT '2022-03-10'::timestamp
707+
UNION SELECT '2023-01-01'::timestamp
708+
UNION SELECT '2023-03-10'::timestamp) AS virtual_table
709+
WHERE datetime_col >= TO_TIMESTAMP('2022-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')
710+
AND datetime_col < TO_TIMESTAMP('2023-01-01 00:00:00.000000', 'YYYY-MM-DD HH24:MI:SS.US')
711+
"""
712+
assert result_object.df.iloc[0]["count"] == 2
753713

754714

755715
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)