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

Update refs to dbt-core macros #97

Merged
merged 1 commit into from
Dec 28, 2022
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
16 changes: 8 additions & 8 deletions integration_tests/macros/get_test_dates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ select
'November' as month_name,
'Nov' as month_name_short,
1623076520 as unix_epoch,
cast('{{ get_test_timestamps()[0] }}' as {{ type_timestamp() }}) as time_stamp,
cast('{{ get_test_timestamps()[1] }}' as {{ type_timestamp() }}) as time_stamp_utc,
cast('2021-06-07' as {{ type_timestamp() }}) as rounded_timestamp,
cast('2021-06-08' as {{ type_timestamp() }}) as rounded_timestamp_utc,
cast('{{ get_test_timestamps()[0] }}' as {{ dbt.type_timestamp() }}) as time_stamp,
cast('{{ get_test_timestamps()[1] }}' as {{ dbt.type_timestamp() }}) as time_stamp_utc,
cast('2021-06-07' as {{ dbt.type_timestamp() }}) as rounded_timestamp,
cast('2021-06-08' as {{ dbt.type_timestamp() }}) as rounded_timestamp_utc,
-- These columns are here to make sure these macros get run during testing:
{{ dbt_date.last_month_number() }} as last_month_number,
{{ dbt_date.last_month_name(short=False) }} as last_month_name,
Expand Down Expand Up @@ -54,10 +54,10 @@ select
'December' as month_name,
'Dec' as month_name_short,
1623076520 as unix_epoch,
cast('{{ get_test_timestamps()[0] }}' as {{ type_timestamp() }}) as time_stamp,
cast('{{ get_test_timestamps()[1] }}' as {{ type_timestamp() }}) as time_stamp_utc,
cast('2021-06-07' as {{ type_timestamp() }}) as rounded_timestamp,
cast('2021-06-08' as {{ type_timestamp() }}) as rounded_timestamp_utc,
cast('{{ get_test_timestamps()[0] }}' as {{ dbt.type_timestamp() }}) as time_stamp,
cast('{{ get_test_timestamps()[1] }}' as {{ dbt.type_timestamp() }}) as time_stamp_utc,
cast('2021-06-07' as {{ dbt.type_timestamp() }}) as rounded_timestamp,
cast('2021-06-08' as {{ dbt.type_timestamp() }}) as rounded_timestamp_utc,
-- These columns are here to make sure these macros get run during testing:
{{ dbt_date.last_month_number() }} as last_month_number,
{{ dbt_date.last_month_name(short=False) }} as last_month_name,
Expand Down
6 changes: 3 additions & 3 deletions macros/_utils/date_spine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% macro default__get_intervals_between(start_date, end_date, datepart) -%}
{%- call statement('get_intervals_between', fetch_result=True) %}

select {{ datediff(start_date, end_date, datepart) }}
select {{ dbt.datediff(start_date, end_date, datepart) }}

{%- endcall -%}

Expand Down Expand Up @@ -35,7 +35,7 @@
date_spine(
"day",
"to_date('01/01/2016', 'mm/dd/yyyy')",
"dateadd(week, 1, current_date)"
"dbt.dateadd(week, 1, current_date)"
) #}


Expand All @@ -53,7 +53,7 @@ all_periods as (

select (
{{
dateadd(
dbt.dateadd(
datepart,
"row_number() over (order by 1) - 1",
start_date
Expand Down
6 changes: 3 additions & 3 deletions macros/calendar_date/convert_timezone.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% macro default__convert_timezone(column, target_tz, source_tz) -%}
convert_timezone('{{ source_tz }}', '{{ target_tz }}',
cast({{ column }} as {{ type_timestamp() }})
cast({{ column }} as {{ dbt.type_timestamp() }})
)
{%- endmacro -%}

Expand All @@ -23,8 +23,8 @@ from_utc_timestamp(

{% macro postgres__convert_timezone(column, target_tz, source_tz) -%}
cast(
cast({{ column }} as {{ type_timestamp() }})
at time zone '{{ source_tz }}' at time zone '{{ target_tz }}' as {{ type_timestamp() }}
cast({{ column }} as {{ dbt.type_timestamp() }})
at time zone '{{ source_tz }}' at time zone '{{ target_tz }}' as {{ dbt.type_timestamp() }}
)
{%- endmacro -%}

Expand Down
2 changes: 1 addition & 1 deletion macros/calendar_date/day_of_month.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
{%- endmacro %}

{%- macro redshift__day_of_month(date) -%}
cast({{ dbt_date.date_part('day', date) }} as {{ type_bigint() }})
cast({{ dbt_date.date_part('day', date) }} as {{ dbt.type_bigint() }})
{%- endmacro %}
8 changes: 4 additions & 4 deletions macros/calendar_date/day_of_week.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
{%- if isoweek -%}
{%- set dow_part = 'isodow' -%}
-- Monday(1) to Sunday (7)
cast({{ dbt_date.date_part(dow_part, date) }} as {{ type_int() }})
cast({{ dbt_date.date_part(dow_part, date) }} as {{ dbt.type_int() }})
{%- else -%}
{%- set dow_part = 'dow' -%}
-- Sunday(1) to Saturday (7)
cast({{ dbt_date.date_part(dow_part, date) }} + 1 as {{ type_int() }})
cast({{ dbt_date.date_part(dow_part, date) }} + 1 as {{ dbt.type_int() }})
{%- endif -%}

{%- endmacro %}
Expand All @@ -75,10 +75,10 @@
case
-- Shift start of week from Sunday (0) to Monday (1)
when {{ dow }} = 0 then 7
else cast({{ dow }} as {{ type_bigint() }})
else cast({{ dow }} as {{ dbt.type_bigint() }})
end
{%- else -%}
cast({{ dow }} + 1 as {{ type_bigint() }})
cast({{ dow }} + 1 as {{ dbt.type_bigint() }})
{%- endif -%}

{%- endmacro %}
2 changes: 1 addition & 1 deletion macros/calendar_date/day_of_year.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
{%- endmacro %}

{%- macro redshift__day_of_year(date) -%}
cast({{ dbt_date.date_part('dayofyear', date) }} as {{ type_bigint() }})
cast({{ dbt_date.date_part('dayofyear', date) }} as {{ dbt.type_bigint() }})
{%- endmacro %}
2 changes: 1 addition & 1 deletion macros/calendar_date/iso_week_of_year.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{%- endmacro -%}

{%- macro _iso_week_of_year(date, week_type) -%}
cast({{ dbt_date.date_part(week_type, date) }} as {{ type_int() }})
cast({{ dbt_date.date_part(week_type, date) }} as {{ dbt.type_int() }})
{%- endmacro %}

{%- macro default__iso_week_of_year(date) -%}
Expand Down
2 changes: 1 addition & 1 deletion macros/calendar_date/iso_week_start.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{%- endmacro -%}

{%- macro _iso_week_start(date, week_type) -%}
cast({{ date_trunc(week_type, date) }} as date)
cast({{ dbt.date_trunc(week_type, date) }} as date)
{%- endmacro %}

{%- macro default__iso_week_start(date) -%}
Expand Down
2 changes: 1 addition & 1 deletion macros/calendar_date/n_days_ago.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- macro n_days_ago(n, date=None, tz=None) -%}
{%-set dt = date if date else dbt_date.today(tz) -%}
{%- set n = n|int -%}
cast({{ dateadd('day', -1 * n, dt) }} as date)
cast({{ dbt.dateadd('day', -1 * n, dt) }} as date)
{%- endmacro -%}
4 changes: 2 additions & 2 deletions macros/calendar_date/n_months_ago.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- macro n_months_ago(n, tz=None) -%}
{%- set n = n|int -%}
{{ date_trunc('month',
dateadd('month', -1 * n,
{{ dbt.date_trunc('month',
dbt.dateadd('month', -1 * n,
dbt_date.today(tz)
)
) }}
Expand Down
4 changes: 2 additions & 2 deletions macros/calendar_date/n_months_away.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- macro n_months_away(n, tz=None) -%}
{%- set n = n|int -%}
{{ date_trunc('month',
dateadd('month', n,
{{ dbt.date_trunc('month',
dbt.dateadd('month', n,
dbt_date.today(tz)
)
) }}
Expand Down
4 changes: 2 additions & 2 deletions macros/calendar_date/n_weeks_ago.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- macro n_weeks_ago(n, tz=None) -%}
{%- set n = n|int -%}
{{ date_trunc('week',
dateadd('week', -1 * n,
{{ dbt.date_trunc('week',
dbt.dateadd('week', -1 * n,
dbt_date.today(tz)
)
) }}
Expand Down
4 changes: 2 additions & 2 deletions macros/calendar_date/n_weeks_away.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- macro n_weeks_away(n, tz=None) -%}
{%- set n = n|int -%}
{{ date_trunc('week',
dateadd('week', n,
{{ dbt.date_trunc('week',
dbt.dateadd('week', n,
dbt_date.today(tz)
)
) }}
Expand Down
2 changes: 1 addition & 1 deletion macros/calendar_date/periods_since.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{%- macro periods_since(date_col, period_name='day', tz=None) -%}
{{ datediff(date_col, dbt_date.now(tz), period_name) }}
{{ dbt.datediff(date_col, dbt_date.now(tz), period_name) }}
{%- endmacro -%}
2 changes: 1 addition & 1 deletion macros/calendar_date/round_timestamp.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% macro round_timestamp(timestamp) %}
{{ date_trunc("day", dateadd("hour", 12, timestamp)) }}
{{ dbt.date_trunc("day", dbt.dateadd("hour", 12, timestamp)) }}
{% endmacro %}
4 changes: 2 additions & 2 deletions macros/calendar_date/week_of_year.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
{%- endmacro -%}

{%- macro default__week_of_year(date) -%}
cast({{ dbt_date.date_part('week', date) }} as {{ type_int() }})
cast({{ dbt_date.date_part('week', date) }} as {{ dbt.type_int() }})
{%- endmacro %}

{%- macro postgres__week_of_year(date) -%}
{# postgresql 'week' returns isoweek. Use to_char instead.
WW = the first week starts on the first day of the year #}
cast(to_char({{ date }}, 'WW') as {{ type_int() }})
cast(to_char({{ date }}, 'WW') as {{ dbt.type_int() }})
{%- endmacro %}
6 changes: 3 additions & 3 deletions macros/calendar_date/week_start.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{%- endmacro -%}

{%- macro default__week_start(date) -%}
cast({{ date_trunc('week', date) }} as date)
cast({{ dbt.date_trunc('week', date) }} as date)
{%- endmacro %}

{%- macro snowflake__week_start(date) -%}
Expand All @@ -13,10 +13,10 @@ cast({{ date_trunc('week', date) }} as date)
dbt_date.day_of_week returns 1, so we subtract 1 to get a 0 offset
#}
{% set off_set = dbt_date.day_of_week(date, isoweek=False) ~ " - 1" %}
cast({{ dateadd("day", "-1 * (" ~ off_set ~ ")", date) }} as date)
cast({{ dbt.dateadd("day", "-1 * (" ~ off_set ~ ")", date) }} as date)
{%- endmacro %}

{%- macro postgres__week_start(date) -%}
-- Sunday as week start date
cast({{ dateadd('day', -1, date_trunc('week', dateadd('day', 1, date))) }} as date)
cast({{ dbt.dateadd('day', -1, dbt.date_trunc('week', dbt.dateadd('day', 1, date))) }} as date)
{%- endmacro %}
6 changes: 3 additions & 3 deletions macros/fiscal_date/get_fiscal_periods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ fscl_year_w13 as (
-- We count the weeks in a 13 week period
-- and separate the 4-5-4 week sequences
mod(cast(
(f.fiscal_week_of_year-1) as {{ type_int() }}
(f.fiscal_week_of_year-1) as {{ dbt.type_int() }}
), 13) as w13_number,
-- Chop weeks into 13 week merch quarters
cast(
least(
floor((f.fiscal_week_of_year-1)/13.0)
, 3)
as {{ type_int() }}) as quarter_number
as {{ dbt.type_int() }}) as quarter_number
from
fscl_year_dates_for_periods f

Expand Down Expand Up @@ -51,7 +51,7 @@ fscl_periods_quarters as (
f.*,
cast((
(f.quarter_number * 3) + f.period_of_quarter
) as {{ type_int() }}) as fiscal_period_number
) as {{ dbt.type_int() }}) as fiscal_period_number
from
fscl_periods f

Expand Down
6 changes: 3 additions & 3 deletions macros/fiscal_date/get_fiscal_year_dates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ weeks as (
d.year_number,
d.month_of_year,
d.date_day as week_start_date,
cast({{ dateadd('day', 6, 'd.date_day') }} as date) as week_end_date
cast({{ dbt.dateadd('day', 6, 'd.date_day') }} as date) as week_end_date
from
date_dimension d
where
Expand Down Expand Up @@ -58,7 +58,7 @@ weeks_at_month_end as (
rank() over
(partition by d.fiscal_year_number
order by
abs({{ datediff('d.week_end_date', 'm.month_end_date', 'day') }})
abs({{ dbt.datediff('d.week_end_date', 'm.month_end_date', 'day') }})

) as closest_to_month_end
from
Expand All @@ -71,7 +71,7 @@ fiscal_year_range as (
select
w.fiscal_year_number,
cast(
{{ dateadd('day', 1,
{{ dbt.dateadd('day', 1,
'lag(w.week_end_date) over(order by w.week_end_date)') }}
as date) as fiscal_year_start_date,
w.week_end_date as fiscal_year_end_date
Expand Down
12 changes: 6 additions & 6 deletions macros/get_base_dates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
{% macro default__get_base_dates(start_date, end_date, n_dateparts, datepart) %}

{%- if start_date and end_date -%}
{%- set start_date="cast('" ~ start_date ~ "' as " ~ type_timestamp() ~ ")" -%}
{%- set end_date="cast('" ~ end_date ~ "' as " ~ type_timestamp() ~ ")" -%}
{%- set start_date="cast('" ~ start_date ~ "' as " ~ dbt.type_timestamp() ~ ")" -%}
{%- set end_date="cast('" ~ end_date ~ "' as " ~ dbt.type_timestamp() ~ ")" -%}

{%- elif n_dateparts and datepart -%}

{%- set start_date = dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%}
{%- set start_date = dbt.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%}
{%- set end_date = dbt_date.tomorrow() -%}
{%- endif -%}

Expand All @@ -26,7 +26,7 @@ with date_spine as

)
select
cast(d.date_{{ datepart }} as {{ type_timestamp() }}) as date_{{ datepart }}
cast(d.date_{{ datepart }} as {{ dbt.type_timestamp() }}) as date_{{ datepart }}
from
date_spine d
{% endmacro %}
Expand All @@ -39,7 +39,7 @@ from

{%- elif n_dateparts and datepart -%}

{%- set start_date = dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%}
{%- set start_date = dbt.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%}
{%- set end_date = dbt_date.tomorrow() -%}
{%- endif -%}

Expand All @@ -55,7 +55,7 @@ with date_spine as

)
select
cast(d.date_{{ datepart }} as {{ type_timestamp() }}) as date_{{ datepart }}
cast(d.date_{{ datepart }} as {{ dbt.type_timestamp() }}) as date_{{ datepart }}
from
date_spine d
{% endmacro %}
Loading