From 36dcae20a6dc1f20c71dc53c528615aaf4933569 Mon Sep 17 00:00:00 2001 From: clausherther Date: Sun, 6 Jun 2021 16:58:24 -0700 Subject: [PATCH 1/4] Make table model --- integration_tests/models/dates.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/models/dates.sql b/integration_tests/models/dates.sql index c12a69f..29c2158 100644 --- a/integration_tests/models/dates.sql +++ b/integration_tests/models/dates.sql @@ -1,6 +1,6 @@ {{ config( - materialized = "ephemeral" + materialized = "table" ) }} {{ dbt_date.get_date_dimension('2015-01-01', '2022-12-31') }} From 026346e56a932f450ce5169ea95f7df8092f1022 Mon Sep 17 00:00:00 2001 From: clausherther Date: Sun, 6 Jun 2021 16:58:40 -0700 Subject: [PATCH 2/4] Clean up macro --- macros/get_base_dates.sql | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/macros/get_base_dates.sql b/macros/get_base_dates.sql index b5286af..d3753c3 100644 --- a/macros/get_base_dates.sql +++ b/macros/get_base_dates.sql @@ -3,17 +3,19 @@ {% endmacro %} {% macro default__get_base_dates(start_date, end_date, n_dateparts, datepart) %} -with date_spine as -( - {% if start_date and end_date %} - {%- set start_date="cast('" ~ start_date ~ "' as " ~ dbt_utils.type_timestamp() ~ ")" -%} - {%- set end_date="cast('" ~ end_date ~ "' as " ~ dbt_utils.type_timestamp() ~ ")" -%} - {% elif n_dateparts and datepart %} +{%- if start_date and end_date -%} +{%- set start_date="cast('" ~ start_date ~ "' as " ~ dbt_utils.type_timestamp() ~ ")" -%} +{%- set end_date="cast('" ~ end_date ~ "' as " ~ dbt_utils.type_timestamp() ~ ")" -%} + +{%- elif n_dateparts and datepart -%} - {%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%} - {%- set end_date = dbt_date.tomorrow() -%} - {% endif %} +{%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%} +{%- set end_date = dbt_date.tomorrow() -%} +{%- endif -%} + +with date_spine as +( {{ dbt_utils.date_spine( datepart=datepart, @@ -30,17 +32,19 @@ from {% endmacro %} {% macro bigquery__get_base_dates(start_date, end_date, n_dateparts, datepart) %} -with date_spine as -( - {% if start_date and end_date %} - {%- set start_date="cast('" ~ start_date ~ "' as date )" -%} - {%- set end_date="cast('" ~ end_date ~ "' as date )" -%} - {% elif n_dateparts and datepart %} +{%- if start_date and end_date -%} +{%- set start_date="cast('" ~ start_date ~ "' as date )" -%} +{%- set end_date="cast('" ~ end_date ~ "' as date )" -%} + +{%- elif n_dateparts and datepart -%} - {%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%} - {%- set end_date = dbt_date.tomorrow() -%} - {% endif %} +{%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%} +{%- set end_date = dbt_date.tomorrow() -%} +{%- endif -%} + +with date_spine as +( {{ dbt_utils.date_spine( datepart=datepart, From ccf2afa13133a40ae9cc02747952d8c162d7d796 Mon Sep 17 00:00:00 2001 From: clausherther Date: Sun, 6 Jun 2021 16:58:57 -0700 Subject: [PATCH 3/4] Add prior_year_iso_week_of_year --- macros/get_date_dimension.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/macros/get_date_dimension.sql b/macros/get_date_dimension.sql index 8f1403d..525b1d1 100644 --- a/macros/get_date_dimension.sql +++ b/macros/get_date_dimension.sql @@ -41,8 +41,8 @@ select {{ dbt_date.iso_week_end('d.prior_year_over_year_date_day') }} as prior_year_iso_week_end_date, {{ dbt_date.iso_week_of_year('d.date_day') }} as iso_week_of_year, - - cast({{ dbt_date.date_part('week', 'd.prior_year_over_year_date_day') }} as {{ dbt_utils.type_int() }}) as prior_year_week_of_year, + {{ dbt_date.week_of_year('d.prior_year_over_year_date_day') }} as prior_year_week_of_year, + {{ dbt_date.iso_week_of_year('d.prior_year_over_year_date_day') }} as prior_year_iso_week_of_year, cast({{ dbt_date.date_part('month', 'd.date_day') }} as {{ dbt_utils.type_int() }}) as month_of_year, {{ dbt_date.month_name('d.date_day', short=false) }} as month_name, @@ -105,8 +105,8 @@ select {{ dbt_date.iso_week_end('d.prior_year_over_year_date_day') }} as prior_year_iso_week_end_date, {{ dbt_date.iso_week_of_year('d.date_day') }} as iso_week_of_year, - - cast({{ dbt_date.date_part('week', 'd.prior_year_over_year_date_day') }} as {{ dbt_utils.type_int() }}) as prior_year_week_of_year, + {{ dbt_date.week_of_year('d.prior_year_over_year_date_day') }} as prior_year_week_of_year, + {{ dbt_date.iso_week_of_year('d.prior_year_over_year_date_day') }} as prior_year_iso_week_of_year, cast({{ dbt_date.date_part('month', 'd.date_day') }} as {{ dbt_utils.type_int() }}) as month_of_year, {{ dbt_date.month_name('d.date_day', short=false) }} as month_name, From d82e49bb5983bc3b9d674df7cf22a3e62b9a78b5 Mon Sep 17 00:00:00 2001 From: clausherther Date: Sun, 6 Jun 2021 17:04:28 -0700 Subject: [PATCH 4/4] Update change log --- CHANGELOG.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2397ec7..49a7354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,22 +1,21 @@ -# dbt-date v0.2.8 +# dbt-date v0.3.0 -## Features - - -## Fixes +## Breaking Changes * Switched `day_of_week` column in `get_date_dimension` from ISO to *not* ISO to align with the rest of the package. [#33](https://github.com/calogica/dbt-date/pull/33) (@davesgonechina) -* Added `day_of_week_iso` column to `get_date_dimension` [#33](https://github.com/calogica/dbt-date/pull/33) (@davesgonechina) -* Refactored Snowflake's `day_name` to not be ISO dependent [#33](https://github.com/calogica/dbt-date/pull/33) (@davesgonechina) - -# dbt-date v0.2.7 ## Features +* Added `day_of_week_iso` column to `get_date_dimension` [#33](https://github.com/calogica/dbt-date/pull/33) (@davesgonechina) + +* Added `prior_year_iso_week_of_year` column to `get_date_dimension` ## Fixes +* Refactored Snowflake's `day_name` to not be ISO dependent [#33](https://github.com/calogica/dbt-date/pull/33) (@davesgonechina) + * Fixed data types for `day_of_*` attributes in Redshift ([#28](https://github.com/calogica/dbt-date/pull/28) by @sparcs) + * Fixed / added support for date parts other than `day` in `get_base_dates` ([#30](https://github.com/calogica/dbt-date/pull/30)) ## Under the hood