Skip to content

Commit 6afc792

Browse files
authored
Update refs to dbt-core macros (#97)
1 parent 656a578 commit 6afc792

21 files changed

+69
-69
lines changed

integration_tests/macros/get_test_dates.sql

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ select
2020
'November' as month_name,
2121
'Nov' as month_name_short,
2222
1623076520 as unix_epoch,
23-
cast('{{ get_test_timestamps()[0] }}' as {{ type_timestamp() }}) as time_stamp,
24-
cast('{{ get_test_timestamps()[1] }}' as {{ type_timestamp() }}) as time_stamp_utc,
25-
cast('2021-06-07' as {{ type_timestamp() }}) as rounded_timestamp,
26-
cast('2021-06-08' as {{ type_timestamp() }}) as rounded_timestamp_utc,
23+
cast('{{ get_test_timestamps()[0] }}' as {{ dbt.type_timestamp() }}) as time_stamp,
24+
cast('{{ get_test_timestamps()[1] }}' as {{ dbt.type_timestamp() }}) as time_stamp_utc,
25+
cast('2021-06-07' as {{ dbt.type_timestamp() }}) as rounded_timestamp,
26+
cast('2021-06-08' as {{ dbt.type_timestamp() }}) as rounded_timestamp_utc,
2727
-- These columns are here to make sure these macros get run during testing:
2828
{{ dbt_date.last_month_number() }} as last_month_number,
2929
{{ dbt_date.last_month_name(short=False) }} as last_month_name,
@@ -54,10 +54,10 @@ select
5454
'December' as month_name,
5555
'Dec' as month_name_short,
5656
1623076520 as unix_epoch,
57-
cast('{{ get_test_timestamps()[0] }}' as {{ type_timestamp() }}) as time_stamp,
58-
cast('{{ get_test_timestamps()[1] }}' as {{ type_timestamp() }}) as time_stamp_utc,
59-
cast('2021-06-07' as {{ type_timestamp() }}) as rounded_timestamp,
60-
cast('2021-06-08' as {{ type_timestamp() }}) as rounded_timestamp_utc,
57+
cast('{{ get_test_timestamps()[0] }}' as {{ dbt.type_timestamp() }}) as time_stamp,
58+
cast('{{ get_test_timestamps()[1] }}' as {{ dbt.type_timestamp() }}) as time_stamp_utc,
59+
cast('2021-06-07' as {{ dbt.type_timestamp() }}) as rounded_timestamp,
60+
cast('2021-06-08' as {{ dbt.type_timestamp() }}) as rounded_timestamp_utc,
6161
-- These columns are here to make sure these macros get run during testing:
6262
{{ dbt_date.last_month_number() }} as last_month_number,
6363
{{ dbt_date.last_month_name(short=False) }} as last_month_name,

macros/_utils/date_spine.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{% macro default__get_intervals_between(start_date, end_date, datepart) -%}
66
{%- call statement('get_intervals_between', fetch_result=True) %}
77

8-
select {{ datediff(start_date, end_date, datepart) }}
8+
select {{ dbt.datediff(start_date, end_date, datepart) }}
99

1010
{%- endcall -%}
1111

@@ -35,7 +35,7 @@
3535
date_spine(
3636
"day",
3737
"to_date('01/01/2016', 'mm/dd/yyyy')",
38-
"dateadd(week, 1, current_date)"
38+
"dbt.dateadd(week, 1, current_date)"
3939
) #}
4040

4141

@@ -53,7 +53,7 @@ all_periods as (
5353

5454
select (
5555
{{
56-
dateadd(
56+
dbt.dateadd(
5757
datepart,
5858
"row_number() over (order by 1) - 1",
5959
start_date

macros/calendar_date/convert_timezone.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{% macro default__convert_timezone(column, target_tz, source_tz) -%}
88
convert_timezone('{{ source_tz }}', '{{ target_tz }}',
9-
cast({{ column }} as {{ type_timestamp() }})
9+
cast({{ column }} as {{ dbt.type_timestamp() }})
1010
)
1111
{%- endmacro -%}
1212

@@ -23,8 +23,8 @@ from_utc_timestamp(
2323

2424
{% macro postgres__convert_timezone(column, target_tz, source_tz) -%}
2525
cast(
26-
cast({{ column }} as {{ type_timestamp() }})
27-
at time zone '{{ source_tz }}' at time zone '{{ target_tz }}' as {{ type_timestamp() }}
26+
cast({{ column }} as {{ dbt.type_timestamp() }})
27+
at time zone '{{ source_tz }}' at time zone '{{ target_tz }}' as {{ dbt.type_timestamp() }}
2828
)
2929
{%- endmacro -%}
3030

macros/calendar_date/day_of_month.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
{%- endmacro %}
44

55
{%- macro redshift__day_of_month(date) -%}
6-
cast({{ dbt_date.date_part('day', date) }} as {{ type_bigint() }})
6+
cast({{ dbt_date.date_part('day', date) }} as {{ dbt.type_bigint() }})
77
{%- endmacro %}

macros/calendar_date/day_of_week.sql

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@
5757
{%- if isoweek -%}
5858
{%- set dow_part = 'isodow' -%}
5959
-- Monday(1) to Sunday (7)
60-
cast({{ dbt_date.date_part(dow_part, date) }} as {{ type_int() }})
60+
cast({{ dbt_date.date_part(dow_part, date) }} as {{ dbt.type_int() }})
6161
{%- else -%}
6262
{%- set dow_part = 'dow' -%}
6363
-- Sunday(1) to Saturday (7)
64-
cast({{ dbt_date.date_part(dow_part, date) }} + 1 as {{ type_int() }})
64+
cast({{ dbt_date.date_part(dow_part, date) }} + 1 as {{ dbt.type_int() }})
6565
{%- endif -%}
6666

6767
{%- endmacro %}
@@ -75,10 +75,10 @@
7575
case
7676
-- Shift start of week from Sunday (0) to Monday (1)
7777
when {{ dow }} = 0 then 7
78-
else cast({{ dow }} as {{ type_bigint() }})
78+
else cast({{ dow }} as {{ dbt.type_bigint() }})
7979
end
8080
{%- else -%}
81-
cast({{ dow }} + 1 as {{ type_bigint() }})
81+
cast({{ dow }} + 1 as {{ dbt.type_bigint() }})
8282
{%- endif -%}
8383

8484
{%- endmacro %}

macros/calendar_date/day_of_year.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
{%- endmacro %}
1212

1313
{%- macro redshift__day_of_year(date) -%}
14-
cast({{ dbt_date.date_part('dayofyear', date) }} as {{ type_bigint() }})
14+
cast({{ dbt_date.date_part('dayofyear', date) }} as {{ dbt.type_bigint() }})
1515
{%- endmacro %}

macros/calendar_date/iso_week_of_year.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{%- endmacro -%}
55

66
{%- macro _iso_week_of_year(date, week_type) -%}
7-
cast({{ dbt_date.date_part(week_type, date) }} as {{ type_int() }})
7+
cast({{ dbt_date.date_part(week_type, date) }} as {{ dbt.type_int() }})
88
{%- endmacro %}
99

1010
{%- macro default__iso_week_of_year(date) -%}

macros/calendar_date/iso_week_start.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{%- endmacro -%}
55

66
{%- macro _iso_week_start(date, week_type) -%}
7-
cast({{ date_trunc(week_type, date) }} as date)
7+
cast({{ dbt.date_trunc(week_type, date) }} as date)
88
{%- endmacro %}
99

1010
{%- macro default__iso_week_start(date) -%}

macros/calendar_date/n_days_ago.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{%- macro n_days_ago(n, date=None, tz=None) -%}
22
{%-set dt = date if date else dbt_date.today(tz) -%}
33
{%- set n = n|int -%}
4-
cast({{ dateadd('day', -1 * n, dt) }} as date)
4+
cast({{ dbt.dateadd('day', -1 * n, dt) }} as date)
55
{%- endmacro -%}

macros/calendar_date/n_months_ago.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{%- macro n_months_ago(n, tz=None) -%}
22
{%- set n = n|int -%}
3-
{{ date_trunc('month',
4-
dateadd('month', -1 * n,
3+
{{ dbt.date_trunc('month',
4+
dbt.dateadd('month', -1 * n,
55
dbt_date.today(tz)
66
)
77
) }}

macros/calendar_date/n_months_away.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{%- macro n_months_away(n, tz=None) -%}
22
{%- set n = n|int -%}
3-
{{ date_trunc('month',
4-
dateadd('month', n,
3+
{{ dbt.date_trunc('month',
4+
dbt.dateadd('month', n,
55
dbt_date.today(tz)
66
)
77
) }}

macros/calendar_date/n_weeks_ago.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{%- macro n_weeks_ago(n, tz=None) -%}
22
{%- set n = n|int -%}
3-
{{ date_trunc('week',
4-
dateadd('week', -1 * n,
3+
{{ dbt.date_trunc('week',
4+
dbt.dateadd('week', -1 * n,
55
dbt_date.today(tz)
66
)
77
) }}

macros/calendar_date/n_weeks_away.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{%- macro n_weeks_away(n, tz=None) -%}
22
{%- set n = n|int -%}
3-
{{ date_trunc('week',
4-
dateadd('week', n,
3+
{{ dbt.date_trunc('week',
4+
dbt.dateadd('week', n,
55
dbt_date.today(tz)
66
)
77
) }}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{%- macro periods_since(date_col, period_name='day', tz=None) -%}
2-
{{ datediff(date_col, dbt_date.now(tz), period_name) }}
2+
{{ dbt.datediff(date_col, dbt_date.now(tz), period_name) }}
33
{%- endmacro -%}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{% macro round_timestamp(timestamp) %}
2-
{{ date_trunc("day", dateadd("hour", 12, timestamp)) }}
2+
{{ dbt.date_trunc("day", dbt.dateadd("hour", 12, timestamp)) }}
33
{% endmacro %}

macros/calendar_date/week_of_year.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
{%- endmacro -%}
55

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

1010
{%- macro postgres__week_of_year(date) -%}
1111
{# postgresql 'week' returns isoweek. Use to_char instead.
1212
WW = the first week starts on the first day of the year #}
13-
cast(to_char({{ date }}, 'WW') as {{ type_int() }})
13+
cast(to_char({{ date }}, 'WW') as {{ dbt.type_int() }})
1414
{%- endmacro %}

macros/calendar_date/week_start.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{%- endmacro -%}
55

66
{%- macro default__week_start(date) -%}
7-
cast({{ date_trunc('week', date) }} as date)
7+
cast({{ dbt.date_trunc('week', date) }} as date)
88
{%- endmacro %}
99

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

1919
{%- macro postgres__week_start(date) -%}
2020
-- Sunday as week start date
21-
cast({{ dateadd('day', -1, date_trunc('week', dateadd('day', 1, date))) }} as date)
21+
cast({{ dbt.dateadd('day', -1, dbt.date_trunc('week', dbt.dateadd('day', 1, date))) }} as date)
2222
{%- endmacro %}

macros/fiscal_date/get_fiscal_periods.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ fscl_year_w13 as (
1313
-- We count the weeks in a 13 week period
1414
-- and separate the 4-5-4 week sequences
1515
mod(cast(
16-
(f.fiscal_week_of_year-1) as {{ type_int() }}
16+
(f.fiscal_week_of_year-1) as {{ dbt.type_int() }}
1717
), 13) as w13_number,
1818
-- Chop weeks into 13 week merch quarters
1919
cast(
2020
least(
2121
floor((f.fiscal_week_of_year-1)/13.0)
2222
, 3)
23-
as {{ type_int() }}) as quarter_number
23+
as {{ dbt.type_int() }}) as quarter_number
2424
from
2525
fscl_year_dates_for_periods f
2626

@@ -51,7 +51,7 @@ fscl_periods_quarters as (
5151
f.*,
5252
cast((
5353
(f.quarter_number * 3) + f.period_of_quarter
54-
) as {{ type_int() }}) as fiscal_period_number
54+
) as {{ dbt.type_int() }}) as fiscal_period_number
5555
from
5656
fscl_periods f
5757

macros/fiscal_date/get_fiscal_year_dates.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ weeks as (
2727
d.year_number,
2828
d.month_of_year,
2929
d.date_day as week_start_date,
30-
cast({{ dateadd('day', 6, 'd.date_day') }} as date) as week_end_date
30+
cast({{ dbt.dateadd('day', 6, 'd.date_day') }} as date) as week_end_date
3131
from
3232
date_dimension d
3333
where
@@ -58,7 +58,7 @@ weeks_at_month_end as (
5858
rank() over
5959
(partition by d.fiscal_year_number
6060
order by
61-
abs({{ datediff('d.week_end_date', 'm.month_end_date', 'day') }})
61+
abs({{ dbt.datediff('d.week_end_date', 'm.month_end_date', 'day') }})
6262

6363
) as closest_to_month_end
6464
from
@@ -71,7 +71,7 @@ fiscal_year_range as (
7171
select
7272
w.fiscal_year_number,
7373
cast(
74-
{{ dateadd('day', 1,
74+
{{ dbt.dateadd('day', 1,
7575
'lag(w.week_end_date) over(order by w.week_end_date)') }}
7676
as date) as fiscal_year_start_date,
7777
w.week_end_date as fiscal_year_end_date

macros/get_base_dates.sql

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
{% macro default__get_base_dates(start_date, end_date, n_dateparts, datepart) %}
66

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

1111
{%- elif n_dateparts and datepart -%}
1212

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

@@ -26,7 +26,7 @@ with date_spine as
2626

2727
)
2828
select
29-
cast(d.date_{{ datepart }} as {{ type_timestamp() }}) as date_{{ datepart }}
29+
cast(d.date_{{ datepart }} as {{ dbt.type_timestamp() }}) as date_{{ datepart }}
3030
from
3131
date_spine d
3232
{% endmacro %}
@@ -39,7 +39,7 @@ from
3939

4040
{%- elif n_dateparts and datepart -%}
4141

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

@@ -55,7 +55,7 @@ with date_spine as
5555

5656
)
5757
select
58-
cast(d.date_{{ datepart }} as {{ type_timestamp() }}) as date_{{ datepart }}
58+
cast(d.date_{{ datepart }} as {{ dbt.type_timestamp() }}) as date_{{ datepart }}
5959
from
6060
date_spine d
6161
{% endmacro %}

0 commit comments

Comments
 (0)