From 607f5f6e86e6cf69fd7866497f7d544fce2ceabd Mon Sep 17 00:00:00 2001 From: sachinthakur96 Date: Wed, 20 Dec 2023 19:07:49 +0530 Subject: [PATCH] Adding --- .../adapter/utils/test_date_spine.py | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/tests/functional/adapter/utils/test_date_spine.py b/tests/functional/adapter/utils/test_date_spine.py index e198da3..4da0035 100644 --- a/tests/functional/adapter/utils/test_date_spine.py +++ b/tests/functional/adapter/utils/test_date_spine.py @@ -33,6 +33,97 @@ actual: intervals expected: expected """ +models__test_date_spine_sql = """ +with generated_dates as ( + {% if target.type == 'postgres' %} + {{ date_spine("day", "'2023-09-01'::date", "'2023-09-10'::date") }} + + {% elif target.type == 'bigquery' or target.type == 'redshift' %} + select cast(date_day as date) as date_day + from ({{ date_spine("day", "'2023-09-01'", "'2023-09-10'") }}) + + {% else %} + {{ date_spine("day", "'2023-09-01'", "'2023-09-10'") }} + {% endif %} +), expected_dates as ( + {% if target.type == 'vertica' %} + select '2023-09-01'::date as expected + union all + select '2023-09-02'::date as expected + union all + select '2023-09-03'::date as expected + union all + select '2023-09-04'::date as expected + union all + select '2023-09-05'::date as expected + union all + select '2023-09-06'::date as expected + union all + select '2023-09-07'::date as expected + union all + select '2023-09-08'::date as expected + union all + select '2023-09-09'::date as expected + + {% elif target.type == 'bigquery' or target.type == 'redshift' %} + select cast('2023-09-01' as date) as expected + union all + select cast('2023-09-02' as date) as expected + union all + select cast('2023-09-03' as date) as expected + union all + select cast('2023-09-04' as date) as expected + union all + select cast('2023-09-05' as date) as expected + union all + select cast('2023-09-06' as date) as expected + union all + select cast('2023-09-07' as date) as expected + union all + select cast('2023-09-08' as date) as expected + union all + select cast('2023-09-09' as date) as expected + + {% else %} + select '2023-09-01' as expected + union all + select '2023-09-02' as expected + union all + select '2023-09-03' as expected + union all + select '2023-09-04' as expected + union all + select '2023-09-05' as expected + union all + select '2023-09-06' as expected + union all + select '2023-09-07' as expected + union all + select '2023-09-08' as expected + union all + select '2023-09-09' as expected + {% endif %} +), joined as ( + select + generated_dates.date_day, + expected_dates.expected + from generated_dates + left join expected_dates on generated_dates.date_day = expected_dates.expected +) + +SELECT * from joined +""" + +models__test_date_spine_yml = """ +version: 2 +models: + - name: test_date_spine + tests: + - assert_equal: + actual: date_day + expected: expected +""" + class BaseGetIntervalsBetween(BaseUtils): @@ -50,6 +141,17 @@ def models(self): +class BaseDateSpine(BaseUtils): + @pytest.fixture(scope="class") + def models(self): + return { + "test_date_spine.yml": models__test_date_spine_yml, + "test_date_spine.sql": self.interpolate_macro_namespace( + models__test_date_spine_sql, "date_spine" + ), + } + + class TestDateSpine(BaseDateSpine): pass