Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extraneous whitespace #529

Merged
merged 12 commits into from
Mar 29, 2022
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# dbt-utils v0.8.2
## Fixes
- Fix union_relations error from [#473](https://github.com/dbt-labs/dbt-utils/pull/473) when no include/exclude parameters are provided ([#505](https://github.com/dbt-labs/dbt-utils/issues/505), [#509](https://github.com/dbt-labs/dbt-utils/pull/509))

# dbt-utils v0.8.1

## New features
Expand All @@ -15,6 +19,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 @@ -24,6 +29,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
84 changes: 45 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ For compatibility details between versions of dbt-core and dbt-utils, [see this
[Materializations](#materializations):
- [insert_by_period](#insert_by_period-source)

---
----
### Schema Tests
#### equal_rowcount ([source](macros/schema_tests/equal_rowcount.sql))
This schema test asserts the that two relations have the same number of rows.
Expand Down Expand Up @@ -310,6 +310,7 @@ models:
to: ref('other_model_name')
field: client_id
from_condition: id <> '4ca448b8-24bf-4b88-96c6-b1609499c38b'
to_condition: created_date >= '2020-01-01'
```

#### mutually_exclusive_ranges ([source](macros/schema_tests/mutually_exclusive_ranges.sql))
Expand Down Expand Up @@ -377,53 +378,58 @@ models:
partition_by: customer_id
gaps: allowed
```
<details>
<summary>Additional `gaps` and `zero_length_range_allowed` examples</summary>

**Understanding the `gaps` argument:**

Here are a number of examples for each allowed `gaps` argument.
* `gaps: not_allowed`: The upper bound of one record must be the lower bound of
the next record.

**Understanding the `gaps` argument:**
Here are a number of examples for each allowed `gaps` argument.
* `gaps: not_allowed`: The upper bound of one record must be the lower bound of
the next record.
| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 1 | 2 |
| 2 | 3 |

| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 1 | 2 |
| 2 | 3 |
* `gaps: allowed` (default): There may be a gap between the upper bound of one
record and the lower bound of the next record.

* `gaps: allowed` (default): There may be a gap between the upper bound of one
record and the lower bound of the next record.
| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 2 | 3 |
| 3 | 4 |

| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 2 | 3 |
| 3 | 4 |
* `gaps: required`: There must be a gap between the upper bound of one record and
the lower bound of the next record (common for date ranges).

* `gaps: required`: There must be a gap between the upper bound of one record and
the lower bound of the next record (common for date ranges).
| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 2 | 3 |
| 4 | 5 |

| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 2 | 3 |
| 4 | 5 |
**Understanding the `zero_length_range_allowed` argument:**
Here are a number of examples for each allowed `zero_length_range_allowed` argument.
* `zero_length_range_allowed: false`: (default) The upper bound of each record must be greater than its lower bound.

**Understanding the `zero_length_range_allowed` argument:**
Here are a number of examples for each allowed `zero_length_range_allowed` argument.
* `zero_length_range_allowed: false`: (default) The upper bound of each record must be greater than its lower bound.
| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 1 | 2 |
| 2 | 3 |

| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 1 | 2 |
| 2 | 3 |
* `zero_length_range_allowed: true`: The upper bound of each record can be greater than or equal to its lower bound.

* `zero_length_range_allowed: true`: The upper bound of each record can be greater than or equal to its lower bound.
| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 2 | 2 |
| 3 | 4 |

| lower_bound | upper_bound |
|-------------|-------------|
| 0 | 1 |
| 2 | 2 |
| 3 | 4 |
</details>

#### sequential_values ([source](macros/schema_tests/sequential_values.sql))
This test confirms that a column contains sequential values. It can be used
Expand Down Expand Up @@ -766,7 +772,7 @@ from {{ ref('my_model') }}
This macro unions together an array of [Relations](https://docs.getdbt.com/docs/writing-code-in-dbt/class-reference/#relation),
even when columns have differing orders in each Relation, and/or some columns are
missing from some relations. Any columns exclusive to a subset of these
relations will be filled with `null` where not present. An new column
relations will be filled with `null` where not present. A new column
(`_dbt_source_relation`) is also added to indicate the source for each record.

**Usage:**
Expand Down
4 changes: 2 additions & 2 deletions macros/cross_db_utils/date_trunc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{{ 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) %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cross-db support, you'll need to do the same thing on each of the adapter-specific macros, like this:

Suggested change
{% macro bigquery__date_trunc(datepart, date) %}
{% macro bigquery__date_trunc(datepart, date) -%}

Again, I haven't applied this everywhere it's necessary - just one example

timestamp_trunc(
Expand Down
4 changes: 2 additions & 2 deletions macros/cross_db_utils/datediff.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
{% endmacro %}


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The leading - doesn't do anything (there is no whitespace prior to it to remove) - this is also true for the trailing - in the endmacro block, but I haven't added this suggestion in every place

Suggested change
{%- 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) %}
Expand Down
2 changes: 1 addition & 1 deletion macros/sql/union.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

{%- set ordered_column_names = column_superset.keys() -%}

{%- if not column_superset.keys() -%}
{% if (include | length > 0 or exclude | length > 0) and not column_superset.keys() %}
{%- set relations_string -%}
{%- for relation in relations -%}
{{ relation.name }}
Expand Down