|
49 | 49 | from tests.integration_tests.test_app import app
|
50 | 50 |
|
51 | 51 | from .base_tests import SupersetTestCase
|
52 |
| -from .conftest import only_postgresql |
53 | 52 |
|
54 | 53 | VIRTUAL_TABLE_INT_TYPES: Dict[str, Pattern[str]] = {
|
55 | 54 | "hive": re.compile(r"^INT_TYPE$"),
|
@@ -666,90 +665,51 @@ def test_filter_on_text_column(text_column_table):
|
666 | 665 | assert result_object.df["count"][0] == 1
|
667 | 666 |
|
668 | 667 |
|
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( |
728 | 692 | {
|
729 | 693 | "metrics": ["count"],
|
730 |
| - "filter": [{"col": "col4", "val": None, "op": expected["operator"]}], |
731 | 694 | "is_timeseries": False,
|
| 695 | + "filter": [], |
| 696 | + "from_dttm": datetime(2022, 1, 1), |
| 697 | + "to_dttm": datetime(2023, 1, 1), |
| 698 | + "granularity": "datetime_col", |
732 | 699 | }
|
733 | 700 | )
|
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 |
753 | 713 |
|
754 | 714 |
|
755 | 715 | @pytest.mark.parametrize(
|
|
0 commit comments