Skip to content

Commit

Permalink
Have union_relations raise exception when include parameter results i…
Browse files Browse the repository at this point in the history
…n no columns (#473)

* Raise exception if no columns in column_superset

* Add relation names to compiler error message

* Add `union_relations` fix to changelog
  • Loading branch information
grahamwetzler authored Jan 24, 2022
1 parent 58b8726 commit 900365a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
- also ignore `dbt_packages/` directory [#463](https://github.com/dbt-labs/dbt-utils/pull/463)

## Fixes
- `type_timestamp` macro now explicitly casts postgres and redshift warehouse timestamp data types as `timestamp without time zone`, to be consistent with Snowflake behaviour (`timestamp_ntz`).
- `type_timestamp` macro now explicitly casts postgres and redshift warehouse timestamp data types as `timestamp without time zone`, to be consistent with Snowflake behaviour (`timestamp_ntz`).
- `union_relations` macro will now raise an exception if the use of `include` or `exclude` results in no columns ([#473](https://github.com/dbt-labs/dbt-utils/pull/473), [#266](https://github.com/dbt-labs/dbt-utils/issues/266)).

## Contributors:
- [grahamwetzler](https://github.com/grahamwetzler) (#473)

# dbt-utils v0.8.0
## 🚨 Breaking changes
Expand Down
15 changes: 15 additions & 0 deletions macros/sql/union.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@

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

{%- if not column_superset.keys() -%}
{%- set relations_string -%}
{%- for relation in relations -%}
{{ relation.name }}
{%- if not loop.last %}, {% endif -%}
{%- endfor -%}
{%- endset -%}

{%- set error_message -%}
There were no columns found to union for relations {{ relations_string }}
{%- endset -%}

{{ exceptions.raise_compiler_error(error_message) }}
{%- endif -%}

{%- for relation in relations %}

(
Expand Down

0 comments on commit 900365a

Please sign in to comment.