Skip to content

Commit

Permalink
Remove extraneous whitespace (#529)
Browse files Browse the repository at this point in the history
* rm whitespace from date_trunc

* datediff

* rm uncessary whitespace control

* change log

* fix CHANGELOG

* address comments
  • Loading branch information
SunriseLong authored Mar 29, 2022
1 parent 839a4fc commit 31577cb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions macros/cross_db_utils/date_trunc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
16 changes: 8 additions & 8 deletions macros/cross_db_utils/datediff.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
{% endmacro %}


{% macro default__datediff(first_date, second_date, datepart) %}
{% macro default__datediff(first_date, second_date, datepart) -%}

datediff(
{{ datepart }},
{{ first_date }},
{{ 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),
cast({{first_date}} as datetime),
{{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))
Expand Down Expand Up @@ -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 %}

0 comments on commit 31577cb

Please sign in to comment.