From 31577cb51dba5f6da06d1ccdb7cc6b4658107392 Mon Sep 17 00:00:00 2001 From: SunriseLong <44146580+SunriseLong@users.noreply.github.com> Date: Tue, 29 Mar 2022 00:03:33 -0400 Subject: [PATCH] Remove extraneous whitespace (#529) * rm whitespace from date_trunc * datediff * rm uncessary whitespace control * change log * fix CHANGELOG * address comments --- CHANGELOG.md | 2 ++ README.md | 1 + macros/cross_db_utils/date_trunc.sql | 8 ++++---- macros/cross_db_utils/datediff.sql | 16 ++++++++-------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 366a4964..da3399cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - `star()` will only alias columns if a prefix/suffix is provided, to allow the unmodified output to still be used in `group by` clauses etc. [#468](https://github.com/dbt-labs/dbt-utils/pull/468) - The `sequential_values` test is now compatible with quoted columns [#479](https://github.com/dbt-labs/dbt-utils/pull/479) - `pivot()` escapes values containing apostrophes [#503](https://github.com/dbt-labs/dbt-utils/pull/503) +- `date_trunc` and `datediff` default macros now have whitespace control to assist with linting and readability [#529](https://github.com/dbt-labs/dbt-utils/pull/529) ## Contributors: - [grahamwetzler](https://github.com/grahamwetzler) (#473) @@ -34,6 +35,7 @@ - [jelstongreen](https://github.com/jelstongreen) (#468) - [armandduijn](https://github.com/armandduijn) (#479) - [mdutoo](https://github.com/mdutoo) (#503) +- [sunriselong](https://github.com/sunriselong) (#529) # dbt-utils v0.8.0 diff --git a/README.md b/README.md index c9caa8cc..581f63ba 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ For compatibility details between versions of dbt-core and dbt-utils, [see this - [insert_by_period](#insert_by_period-source) ---- +======= ### Generic Tests #### equal_rowcount ([source](macros/generic_tests/equal_rowcount.sql)) Asserts that two relations have the same number of rows. diff --git a/macros/cross_db_utils/date_trunc.sql b/macros/cross_db_utils/date_trunc.sql index cba3346b..f9d0364b 100644 --- a/macros/cross_db_utils/date_trunc.sql +++ b/macros/cross_db_utils/date_trunc.sql @@ -2,14 +2,14 @@ {{ return(adapter.dispatch('date_trunc', 'dbt_utils') (datepart, date)) }} {%- endmacro %} -{% macro default__date_trunc(datepart, date) %} +{% macro default__date_trunc(datepart, date) -%} date_trunc('{{datepart}}', {{date}}) -{% endmacro %} +{%- endmacro %} -{% macro bigquery__date_trunc(datepart, date) %} +{% macro bigquery__date_trunc(datepart, date) -%} timestamp_trunc( cast({{date}} as timestamp), {{datepart}} ) -{% endmacro %} +{%- endmacro %} diff --git a/macros/cross_db_utils/datediff.sql b/macros/cross_db_utils/datediff.sql index 42dd738e..2b5d6613 100644 --- a/macros/cross_db_utils/datediff.sql +++ b/macros/cross_db_utils/datediff.sql @@ -3,7 +3,7 @@ {% endmacro %} -{% macro default__datediff(first_date, second_date, datepart) %} +{% macro default__datediff(first_date, second_date, datepart) -%} datediff( {{ datepart }}, @@ -11,10 +11,10 @@ {{ second_date }} ) -{% endmacro %} +{%- endmacro %} -{% macro bigquery__datediff(first_date, second_date, datepart) %} +{% macro bigquery__datediff(first_date, second_date, datepart) -%} datetime_diff( cast({{second_date}} as datetime), @@ -22,9 +22,9 @@ {{datepart}} ) -{% endmacro %} +{%- endmacro %} -{% macro postgres__datediff(first_date, second_date, datepart) %} +{% macro postgres__datediff(first_date, second_date, datepart) -%} {% if datepart == 'year' %} (date_part('year', ({{second_date}})::date) - date_part('year', ({{first_date}})::date)) @@ -55,12 +55,12 @@ {{ exceptions.raise_compiler_error("Unsupported datepart for macro datediff in postgres: {!r}".format(datepart)) }} {% endif %} -{% endmacro %} +{%- endmacro %} {# redshift should use default instead of postgres #} -{% macro redshift__datediff(first_date, second_date, datepart) %} +{% macro redshift__datediff(first_date, second_date, datepart) -%} {{ return(dbt_utils.default__datediff(first_date, second_date, datepart)) }} -{% endmacro %} +{%- endmacro %}