Skip to content

Commit

Permalink
Use the relation object passed into get_column_values, instead of mak…
Browse files Browse the repository at this point in the history
…ing 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
  • Loading branch information
joellabes authored Nov 11, 2021
1 parent 4457e42 commit 3a5d30e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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), [#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

Expand Down
10 changes: 5 additions & 5 deletions integration_tests/models/sql/test_get_column_values.sql
Original file line number Diff line number Diff line change
@@ -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 %}
Expand All @@ -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 %}
Expand Down
6 changes: 3 additions & 3 deletions macros/sql/get_column_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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) %}

Expand Down

0 comments on commit 3a5d30e

Please sign in to comment.