From ab141228a0dcb88a4c30b53acfda4817744edac8 Mon Sep 17 00:00:00 2001 From: Joel Labes Date: Wed, 10 Nov 2021 10:20:01 +1300 Subject: [PATCH 1/3] Use the relation object passed into get_column_values, instead of making our own --- CHANGELOG.md | 6 ++++++ macros/sql/get_column_values.sql | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 150b71a2..aecc9fb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# dbt-utils v0.7.4 +🚨 This is a compatibility release in preparation for `dbt-core` v1.0.0 (🎉). Projects using dbt-utils 0.7.4 with dbt-core v1.0.0 can expect to see a deprecation warning. This will be resolved in dbt_utils v0.8.0. + +## Fixes +- `get_column_values()` now works correctly with mixed-quoting styles on Snowflake ([#424](https://github.com/dbt-labs/dbt-utils/issues/424), [PR tk]) + # dbt-utils v0.7.4b1 This is a compatibility release in preparation for `dbt-core` v1.0.0 (🎉). When dbt-core 1.0.0 hits release candidate status, we will release the final version of 0.7.4 diff --git a/macros/sql/get_column_values.sql b/macros/sql/get_column_values.sql index 1f79a455..c2f65aff 100644 --- a/macros/sql/get_column_values.sql +++ b/macros/sql/get_column_values.sql @@ -9,9 +9,9 @@ {{ return('') }} {% endif %} - {%- set target_relation = adapter.get_relation(database=table.database, - schema=table.schema, - identifier=table.identifier) -%} + {# Not all relations are tables. Renaming for internal clarity without breaking functionality for anyone using named arguments #} + {# TODO: Change the method signature in a future 0.x.0 release #} + {%- set target_relation = table -%} {%- call statement('get_column_values', fetch_result=true) %} From 3180e94b1fc1ca28027a1a47c65183925ca5e8cd Mon Sep 17 00:00:00 2001 From: Joel Labes Date: Wed, 10 Nov 2021 10:27:13 +1300 Subject: [PATCH 2/3] Rename variables in get column value test to be clearer --- .../models/sql/test_get_column_values.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integration_tests/models/sql/test_get_column_values.sql b/integration_tests/models/sql/test_get_column_values.sql index 8e6f5b45..36214984 100644 --- a/integration_tests/models/sql/test_get_column_values.sql +++ b/integration_tests/models/sql/test_get_column_values.sql @@ -1,13 +1,13 @@ -{% set columns = dbt_utils.get_column_values(ref('data_get_column_values'), 'field', default=[], order_by="field") %} +{% set column_values = dbt_utils.get_column_values(ref('data_get_column_values'), 'field', default=[], order_by="field") %} {% if target.type == 'snowflake' %} select - {% for column in columns -%} + {% for val in column_values -%} - sum(case when field = '{{ column }}' then 1 else 0 end) as count_{{ column }} + sum(case when field = '{{ val }}' then 1 else 0 end) as count_{{ val }} {%- if not loop.last %},{% endif -%} {%- endfor %} @@ -17,9 +17,9 @@ from {{ ref('data_get_column_values') }} {% else %} select - {% for column in columns -%} + {% for val in column_values -%} - {{dbt_utils.safe_cast("sum(case when field = '" ~ column ~ "' then 1 else 0 end)", dbt_utils.type_string()) }} as count_{{ column }} + {{dbt_utils.safe_cast("sum(case when field = '" ~ val ~ "' then 1 else 0 end)", dbt_utils.type_string()) }} as count_{{ val }} {%- if not loop.last %},{% endif -%} {%- endfor %} From 6b28a1e707e70ba87e08134a25a69e973a401e3d Mon Sep 17 00:00:00 2001 From: Joel Labes Date: Wed, 10 Nov 2021 10:29:55 +1300 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aecc9fb6..f8be8d9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ 🚨 This is a compatibility release in preparation for `dbt-core` v1.0.0 (🎉). Projects using dbt-utils 0.7.4 with dbt-core v1.0.0 can expect to see a deprecation warning. This will be resolved in dbt_utils v0.8.0. ## Fixes -- `get_column_values()` now works correctly with mixed-quoting styles on Snowflake ([#424](https://github.com/dbt-labs/dbt-utils/issues/424), [PR tk]) +- `get_column_values()` now works correctly with mixed-quoting styles on Snowflake ([#424](https://github.com/dbt-labs/dbt-utils/issues/424), [#440](https://github.com/dbt-labs/dbt-utils/pull/440)) # dbt-utils v0.7.4b1 This is a compatibility release in preparation for `dbt-core` v1.0.0 (🎉). When dbt-core 1.0.0 hits release candidate status, we will release the final version of 0.7.4