Skip to content

Commit 3a5d30e

Browse files
authored
Use the relation object passed into get_column_values, instead of making our own (#440)
* Use the relation object passed into get_column_values, instead of making our own * Rename variables in get column value test to be clearer * Update CHANGELOG.md
1 parent 4457e42 commit 3a5d30e

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# dbt-utils v0.7.4
2+
🚨 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.
3+
4+
## Fixes
5+
- `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))
6+
17
# dbt-utils v0.7.4b1
28
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
39

integration_tests/models/sql/test_get_column_values.sql

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
{% set columns = dbt_utils.get_column_values(ref('data_get_column_values'), 'field', default=[], order_by="field") %}
2+
{% set column_values = dbt_utils.get_column_values(ref('data_get_column_values'), 'field', default=[], order_by="field") %}
33

44

55
{% if target.type == 'snowflake' %}
66

77
select
8-
{% for column in columns -%}
8+
{% for val in column_values -%}
99

10-
sum(case when field = '{{ column }}' then 1 else 0 end) as count_{{ column }}
10+
sum(case when field = '{{ val }}' then 1 else 0 end) as count_{{ val }}
1111
{%- if not loop.last %},{% endif -%}
1212

1313
{%- endfor %}
@@ -17,9 +17,9 @@ from {{ ref('data_get_column_values') }}
1717
{% else %}
1818

1919
select
20-
{% for column in columns -%}
20+
{% for val in column_values -%}
2121

22-
{{dbt_utils.safe_cast("sum(case when field = '" ~ column ~ "' then 1 else 0 end)", dbt_utils.type_string()) }} as count_{{ column }}
22+
{{dbt_utils.safe_cast("sum(case when field = '" ~ val ~ "' then 1 else 0 end)", dbt_utils.type_string()) }} as count_{{ val }}
2323
{%- if not loop.last %},{% endif -%}
2424

2525
{%- endfor %}

macros/sql/get_column_values.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
{{ return('') }}
1010
{% endif %}
1111

12-
{%- set target_relation = adapter.get_relation(database=table.database,
13-
schema=table.schema,
14-
identifier=table.identifier) -%}
12+
{# Not all relations are tables. Renaming for internal clarity without breaking functionality for anyone using named arguments #}
13+
{# TODO: Change the method signature in a future 0.x.0 release #}
14+
{%- set target_relation = table -%}
1515

1616
{%- call statement('get_column_values', fetch_result=true) %}
1717

0 commit comments

Comments
 (0)