Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cast day_of attributes to bigint on Redshift #28

Merged
merged 3 commits into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions macros/calendar_date/day_of_month.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
{{ dbt_date.date_part('day', date) }}
{%- endmacro %}

{%- macro redshift__day_of_month(date) -%}
cast({{ dbt_date.date_part('day', date) }} as {{ dbt_utils.type_bigint() }})
{%- endmacro %}
23 changes: 20 additions & 3 deletions macros/calendar_date/day_of_week.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
{{ dbt_date.date_part(dow_part, date) }}
{%- else -%}
{%- set dow_part = 'dayofweek' -%}
case
case
when {{ dbt_date.date_part(dow_part, date) }} = 7 then 1
else {{ dbt_date.date_part(dow_part, date) }} + 1
end
{%- endif -%}



{%- endmacro %}

{%- macro bigquery__day_of_week(date, isoweek) -%}
Expand Down Expand Up @@ -65,3 +65,20 @@
{%- endif -%}

{%- endmacro %}


{%- macro redshift__day_of_week(date, isoweek) -%}

{%- set dow = dbt_date.date_part('dayofweek', date) -%}

{%- if isoweek -%}
case
-- Shift start of week from Sunday (0) to Monday (1)
when {{ dow }} = 0 then 7
else cast({{ dow }} as {{ dbt_utils.type_bigint() }})
end
{%- else -%}
cast({{ dow }} + 1 as {{ dbt_utils.type_bigint() }})
{%- endif -%}

{%- endmacro %}
4 changes: 4 additions & 0 deletions macros/calendar_date/day_of_year.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
{%- macro postgres__day_of_year(date) -%}
{{ dbt_date.date_part('doy', date) }}
{%- endmacro %}

{%- macro redshift__day_of_year(date) -%}
cast({{ dbt_date.date_part('dayofyear', date) }} as {{ dbt_utils.type_bigint() }})
{%- endmacro %}