From 53703b90b5ee16e6ac5ab8797824a09cedb64f70 Mon Sep 17 00:00:00 2001 From: Martin Jung Date: Thu, 7 Sep 2023 23:19:10 +1000 Subject: [PATCH 1/2] Output '*' in union_relations when no columns are found in compile mode This is to handle the scenario where the upstream relations haven't been run, and you run SQLFluff against a model using union_relations, with source_column_name=None. --- macros/sql/union.sql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/macros/sql/union.sql b/macros/sql/union.sql index ac289e2f..0d1f8961 100644 --- a/macros/sql/union.sql +++ b/macros/sql/union.sql @@ -103,6 +103,12 @@ cast({{ dbt.string_literal(relation) }} as {{ dbt.type_string() }}) as {{ source_column_name }}, {%- endif %} + /* No columns from any of the relations. + This star is only output during dbt compile, and exists to keep SQLFluff happy. */ + {% if dbt_command == 'compile' and ordered_column_names|length == 0 %} + * + {% endif %} + {% for col_name in ordered_column_names -%} {%- set col = column_superset[col_name] %} From 47ac8c0b8fd3e3065b83d27e13288b5aa834d4dd Mon Sep 17 00:00:00 2001 From: Martin Jung Date: Thu, 7 Sep 2023 23:32:18 +1000 Subject: [PATCH 2/2] Add entry to CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16e296f7..5b31e2da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * Use QUALIFY clause in `deduplicate` macro for Redshift by @yauhen-sobaleu in https://github.com/dbt-labs/dbt-utils/pull/811 * get redshift external tables by @brendan-cook-87 in https://github.com/dbt-labs/dbt-utils/pull/753 * Equality test will now raise an error when the second model has less columns than the first by @rlh1994 in https://github.com/dbt-labs/dbt-utils/pull/765 +* union_relations macro now outputs '*' in compile mode when the upstream relations haven't been built, such as when running SQLFluff on new models ### Documentation @@ -43,6 +44,7 @@ * @yamotech made their first contribution in https://github.com/dbt-labs/dbt-utils/pull/876 * @PChambino made their first contribution in https://github.com/dbt-labs/dbt-utils/pull/853 * @pruoff made their first contribution in https://github.com/dbt-labs/dbt-utils/pull/856 +* @martinshjung made their first contribution in https://github.com/dbt-labs/dbt-utils/pull/832 **Full Changelog**: https://github.com/dbt-labs/dbt-utils/compare/1.1.1...1.2.0