Skip to content

Commit

Permalink
Update calls to dbt-core date macros
Browse files Browse the repository at this point in the history
  • Loading branch information
clausherther committed Dec 28, 2022
1 parent 2428244 commit 3df4494
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ with metric_values as (
with grouped_metric_values as (

select
{{ date_trunc(period, date_column_name) }} as metric_period,
{{ dbt.date_trunc(period, date_column_name) }} as metric_period,
{{ group_by | join(",") ~ "," if group_by }}
sum({{ column_name }}) as agg_metric_value
from
Expand Down Expand Up @@ -139,10 +139,10 @@ from
where

metric_period >= cast(
{{ dateadd(period, -test_periods, date_trunc(period, dbt_date.now())) }}
{{ dbt.dateadd(period, -test_periods, dbt.date_trunc(period, dbt_date.now())) }}
as {{ dbt_expectations.type_timestamp() }})
and
metric_period < {{ date_trunc(period, dbt_date.now()) }}
metric_period < {{ dbt.date_trunc(period, dbt_date.now()) }}
and

not (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ with base_dates as (
Filtering the spine only where this remainder == 0 will return a spine with every other day as desired, i.e. [2020-01-01, 2020-01-03, 2020-01-05, ...]
#}
where mod(
cast({{ datediff("'" ~ start_date ~ "'", 'date_' ~ date_part, date_part) }} as {{ dbt.type_int() }}),
cast({{ dbt.datediff("'" ~ start_date ~ "'", 'date_' ~ date_part, date_part) }} as {{ dbt.type_int() }}),
cast({{interval}} as {{ dbt.type_int() }})
) = 0
{% endif %}
Expand All @@ -68,7 +68,7 @@ model_data as (
select
{% if not interval %}

cast({{ date_trunc(date_part, date_col) }} as {{ dbt_expectations.type_datetime() }}) as date_{{ date_part }},
cast({{ dbt.date_trunc(date_part, date_col) }} as {{ dbt_expectations.type_datetime() }}) as date_{{ date_part }},

{% else %}
{#
Expand All @@ -80,13 +80,13 @@ model_data as (
subtracting that number of days from the observations will produce records [2020-01-01, 2020-01-01, 2020-01-03, 2020-01-11, 2020-01-11],
all of which align with records from the interval-date spine
#}
{{dateadd(
{{ dbt.dateadd(
date_part,
"mod(
cast(" ~ datediff("'" ~ start_date ~ "'", date_col, date_part) ~ " as " ~ dbt.type_int() ~ " ),
cast(" ~ interval ~ " as " ~ dbt.type_int() ~ " )
) * (-1)",
"cast( " ~ date_trunc(date_part, date_col) ~ " as " ~ dbt_expectations.type_datetime() ~ ")"
"cast( " ~ dbt.date_trunc(date_part, date_col) ~ " as " ~ dbt_expectations.type_datetime() ~ ")"
)}} as date_{{ date_part }},

{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ outdated_grouped_timestamps as (
-- are the max timestamps per group older than the specified cutoff?
latest_timestamp_column <
cast(
{{ dateadd(datepart, interval * -1, dbt_date.now()) }}
{{ dbt.dateadd(datepart, interval * -1, dbt_date.now()) }}
as {{ dbt_expectations.type_timestamp() }}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ where
-- to avoid false negatives
coalesce(max_timestamp, cast('{{ default_start_date }}' as {{ dbt_expectations.type_timestamp() }}))
<
cast({{ dateadd(datepart, interval * -1, dbt_date.now()) }} as {{ dbt_expectations.type_timestamp() }})
cast({{ dbt.dateadd(datepart, interval * -1, dbt_date.now()) }} as {{ dbt_expectations.type_timestamp() }})

{% endmacro %}

0 comments on commit 3df4494

Please sign in to comment.