From 106e55afe85dd8e4e6ff43d6f3aa74da3fb484a1 Mon Sep 17 00:00:00 2001 From: Graham Wetzler Date: Thu, 30 Dec 2021 13:53:08 -0600 Subject: [PATCH 1/3] Raise exception if no columns in column_superset --- macros/sql/union.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/macros/sql/union.sql b/macros/sql/union.sql index 13bafe31..be0b1a80 100644 --- a/macros/sql/union.sql +++ b/macros/sql/union.sql @@ -61,6 +61,10 @@ {%- set ordered_column_names = column_superset.keys() -%} + {%- if not column_superset.keys() -%} + {{ exceptions.raise_compiler_error("No columns to union.") }} + {%- endif -%} + {%- for relation in relations %} ( From 62740ab61fd2e12b30fab32e3c33dcc5849f6b75 Mon Sep 17 00:00:00 2001 From: Graham Wetzler Date: Fri, 14 Jan 2022 11:45:04 -0600 Subject: [PATCH 2/3] Add relation names to compiler error message --- macros/sql/union.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/macros/sql/union.sql b/macros/sql/union.sql index be0b1a80..009a765a 100644 --- a/macros/sql/union.sql +++ b/macros/sql/union.sql @@ -62,7 +62,18 @@ {%- set ordered_column_names = column_superset.keys() -%} {%- if not column_superset.keys() -%} - {{ exceptions.raise_compiler_error("No columns to union.") }} + {%- 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 %} From 6d3aa252a91108057decb9483594993a3a3c2526 Mon Sep 17 00:00:00 2001 From: Graham Wetzler Date: Mon, 24 Jan 2022 10:22:16 -0600 Subject: [PATCH 3/3] Add `union_relations` fix to changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1861c41..59145411 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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