Skip to content

Commit

Permalink
Merge pull request #35 from calogica/update/date-dim-columns
Browse files Browse the repository at this point in the history
Add `prior_year_iso_week_of_year` column to `get_date_dimension`
  • Loading branch information
clausherther authored Jun 7, 2021
2 parents 370d472 + d82e49b commit a6b7df4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
17 changes: 8 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/models/dates.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{
config(
materialized = "ephemeral"
materialized = "table"
)
}}
{{ dbt_date.get_date_dimension('2015-01-01', '2022-12-31') }}
40 changes: 22 additions & 18 deletions macros/get_base_dates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions macros/get_date_dimension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a6b7df4

Please sign in to comment.