From d98279043acb1c958b43aeff3e43f074328bbb3c Mon Sep 17 00:00:00 2001 From: Anders Swanson Date: Sun, 30 May 2021 12:46:54 -0400 Subject: [PATCH 1/3] more succint, easier to shim --- integration_tests/macros/get_test_dates.sql | 64 +++++---------------- 1 file changed, 15 insertions(+), 49 deletions(-) diff --git a/integration_tests/macros/get_test_dates.sql b/integration_tests/macros/get_test_dates.sql index 0ccdbb7..56e4044 100644 --- a/integration_tests/macros/get_test_dates.sql +++ b/integration_tests/macros/get_test_dates.sql @@ -1,8 +1,4 @@ {% macro get_test_dates() -%} - {{ return(adapter.dispatch('get_test_dates', packages = dbt_date_integration_tests._get_utils_namespaces()) ()) }} -{%- endmacro %} - -{% macro default__get_test_dates() -%} select cast('2020-11-29' as date) as date_day, cast('2020-11-28' as date) as prior_date_day, @@ -15,7 +11,7 @@ select 334 as day_of_year, cast('2020-11-29' as date) as week_start_date, cast('2020-12-05' as date) as week_end_date, - 48 as week_of_year, + {{ get_test_week_of_year()[0] }} as week_of_year, -- in ISO terms, this is the end of the prior week cast('2020-11-23' as date) as iso_week_start_date, cast('2020-11-29' as date) as iso_week_end_date, @@ -37,8 +33,7 @@ select 336 as day_of_year, cast('2020-11-29' as date) as week_start_date, cast('2020-12-05' as date) as week_end_date, - 48 as week_of_year, - + {{ get_test_week_of_year()[1] }} as week_of_year, cast('2020-11-30' as date) as iso_week_start_date, cast('2020-12-06' as date) as iso_week_end_date, 49 as iso_week_of_year, @@ -46,47 +41,18 @@ select 'Dec' as month_name_short {%- endmacro %} -{% macro snowflake__get_test_dates() -%} -select - cast('2020-11-29' as date) as date_day, - cast('2020-11-28' as date) as prior_date_day, - cast('2020-11-30' as date) as next_date_day, - 'Sunday' as day_name, - 'Sun' as day_name_short, - 29 as day_of_month, - 1 as day_of_week, - 7 as iso_day_of_week, - 334 as day_of_year, - cast('2020-11-29' as date) as week_start_date, - cast('2020-12-05' as date) as week_end_date, - 48 as week_of_year, - -- in ISO terms, this is the end of the prior week - cast('2020-11-23' as date) as iso_week_start_date, - cast('2020-11-29' as date) as iso_week_end_date, - 48 as iso_week_of_year, - 'November' as month_name, - 'Nov' as month_name_short - - union all - -select - cast('2020-12-01' as date) as date_day, - cast('2020-11-30' as date) as prior_date_day, - cast('2020-12-02' as date) as next_date_day, - 'Tuesday' as day_name, - 'Tue' as day_name_short, - 1 as day_of_month, - 3 as day_of_week, - 2 as iso_day_of_week, - 336 as day_of_year, - cast('2020-11-29' as date) as week_start_date, - cast('2020-12-05' as date) as week_end_date, - -- Snowflake returns ISO week numbers with the standard config - 49 as week_of_year, +{% macro get_test_week_of_year() -%} + {{ return(adapter.dispatch('get_test_week_of_year', packages = dbt_date_integration_tests._get_utils_namespaces()) ()) }} +{%- endmacro %} - cast('2020-11-30' as date) as iso_week_start_date, - cast('2020-12-06' as date) as iso_week_end_date, - 49 as iso_week_of_year, - 'December' as month_name, - 'Dec' as month_name_short +{% macro default__get_test_week_of_year() -%} + {{ log("in default macro", info=True) }} + {# weeks_of_year for '2020-11-29' and '2020-12-01', respectively #} + {{ return([48,48]) }} {%- endmacro %} + +{% macro snowflake__get_test_week_of_year() -%} + {# weeks_of_year for '2020-11-29' and '2020-12-01', respectively #} + {# Snowflake uses ISO year #} + {{ return([48,49]) }} +{%- endmacro %} \ No newline at end of file From 003ce03ffec63c3714ec3f6732f9a9051e223cf8 Mon Sep 17 00:00:00 2001 From: Anders Swanson Date: Sun, 30 May 2021 13:36:40 -0400 Subject: [PATCH 2/3] simplify dbt-date namespace; aligns with dbt-utils --- integration_tests/dbt_project.yml | 1 + integration_tests/macros/_get_utils_namespaces.sql | 4 ---- integration_tests/macros/get_test_dates.sql | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 integration_tests/macros/_get_utils_namespaces.sql diff --git a/integration_tests/dbt_project.yml b/integration_tests/dbt_project.yml index f476938..f795ceb 100644 --- a/integration_tests/dbt_project.yml +++ b/integration_tests/dbt_project.yml @@ -20,6 +20,7 @@ clean-targets: require-dbt-version: ">=0.18.1" vars: + dbt_date_dispatch_list: ['dbt_date_integration_tests'] "dbt_date:time_zone": "America/Los_Angeles" quoting: diff --git a/integration_tests/macros/_get_utils_namespaces.sql b/integration_tests/macros/_get_utils_namespaces.sql deleted file mode 100644 index b28dd89..0000000 --- a/integration_tests/macros/_get_utils_namespaces.sql +++ /dev/null @@ -1,4 +0,0 @@ -{% macro _get_utils_namespaces() %} - {% set override_namespaces = var('dbt_date_integration_tests_dispatch_list', []) %} - {% do return(override_namespaces + ['dbt_date_integration_tests']) %} -{% endmacro %} diff --git a/integration_tests/macros/get_test_dates.sql b/integration_tests/macros/get_test_dates.sql index 56e4044..615da39 100644 --- a/integration_tests/macros/get_test_dates.sql +++ b/integration_tests/macros/get_test_dates.sql @@ -42,7 +42,7 @@ select {%- endmacro %} {% macro get_test_week_of_year() -%} - {{ return(adapter.dispatch('get_test_week_of_year', packages = dbt_date_integration_tests._get_utils_namespaces()) ()) }} + {{ return(adapter.dispatch('get_test_week_of_year', packages = dbt_date._get_utils_namespaces()) ()) }} {%- endmacro %} {% macro default__get_test_week_of_year() -%} From ccfcf699f8095815d4af00d04cea36f1e65ae5c0 Mon Sep 17 00:00:00 2001 From: clausherther Date: Sun, 30 May 2021 16:08:03 -0700 Subject: [PATCH 3/3] Remove log statement --- integration_tests/macros/get_test_dates.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration_tests/macros/get_test_dates.sql b/integration_tests/macros/get_test_dates.sql index 615da39..fe8cfd4 100644 --- a/integration_tests/macros/get_test_dates.sql +++ b/integration_tests/macros/get_test_dates.sql @@ -46,7 +46,6 @@ select {%- endmacro %} {% macro default__get_test_week_of_year() -%} - {{ log("in default macro", info=True) }} {# weeks_of_year for '2020-11-29' and '2020-12-01', respectively #} {{ return([48,48]) }} {%- endmacro %} @@ -55,4 +54,4 @@ select {# weeks_of_year for '2020-11-29' and '2020-12-01', respectively #} {# Snowflake uses ISO year #} {{ return([48,49]) }} -{%- endmacro %} \ No newline at end of file +{%- endmacro %}