diff --git a/CHANGELOG.md b/CHANGELOG.md index 57462d1e1..239e6130e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # dbt-utils v0.7.0 (unreleased) * Added optional `where` clause in `unique_combination_of_columns` test macro [#295](https://github.com/fishtown-analytics/dbt-utils/pull/295) [findinpath](https://github.com/findinpath) +## Breaking changes: +- [Potential breaking change] The BigQuery implementations of `dateadd` and `datediff` macros now use `timestamp` types instead of `datetime` types, to be more consistent with other warehouses ([#318](https://github.com/fishtown-analytics/dbt-utils/pull/318)) + ## Features * Add new `accepted_range` test ([#276](https://github.com/fishtown-analytics/dbt-utils/pull/276) [@joellabes](https://github.com/joellabes)) * Make `expression_is_true` work as a column test (code originally in [#226](https://github.com/fishtown-analytics/dbt-utils/pull/226/) from [@elliottohara](https://github.com/elliottohara), merged via [#313]) diff --git a/integration_tests/models/schema_tests/test_recency.sql b/integration_tests/models/schema_tests/test_recency.sql index d300e572b..d44b5bc18 100644 --- a/integration_tests/models/schema_tests/test_recency.sql +++ b/integration_tests/models/schema_tests/test_recency.sql @@ -1,12 +1,2 @@ - -{% if target.type == 'postgres' %} - select {{ dbt_utils.date_trunc('day', dbt_utils.current_timestamp()) }} as today - -{% else %} - -select - cast({{ dbt_utils.date_trunc('day', dbt_utils.current_timestamp()) }} as datetime) as today - -{% endif %} diff --git a/macros/cross_db_utils/dateadd.sql b/macros/cross_db_utils/dateadd.sql index 71a882800..1455083ac 100644 --- a/macros/cross_db_utils/dateadd.sql +++ b/macros/cross_db_utils/dateadd.sql @@ -16,8 +16,8 @@ {% macro bigquery__dateadd(datepart, interval, from_date_or_timestamp) %} - datetime_add( - cast( {{ from_date_or_timestamp }} as datetime), + timestamp_add( + cast( {{ from_date_or_timestamp }} as timestamp), interval {{ interval }} {{ datepart }} ) diff --git a/macros/cross_db_utils/datediff.sql b/macros/cross_db_utils/datediff.sql index ab5559d7c..b91f8e86b 100644 --- a/macros/cross_db_utils/datediff.sql +++ b/macros/cross_db_utils/datediff.sql @@ -16,9 +16,9 @@ {% macro bigquery__datediff(first_date, second_date, datepart) %} - datetime_diff( - cast({{second_date}} as datetime), - cast({{first_date}} as datetime), + timestamp_diff( + cast({{second_date}} as timestamp_diff), + cast({{first_date}} as timestamp_diff), {{datepart}} ) diff --git a/macros/schema_tests/recency.sql b/macros/schema_tests/recency.sql index cc17e8475..0a3306fc7 100644 --- a/macros/schema_tests/recency.sql +++ b/macros/schema_tests/recency.sql @@ -12,6 +12,6 @@ select end as error_result from {{model}} where {{column_name}} >= - {{dbt_utils.dateadd(datepart, interval * -1, dbt_utils.current_timestamp())}} + {{ dbt_utils.dateadd(datepart, interval * -1, dbt_utils.current_timestamp()) }} {% endmacro %}