Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the relation object passed into get_column_values, instead of making our own #440

Merged
merged 3 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nitpicky but should we say what we did / changed to make it work with mixed-quoting styles on Snowflake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think release notes can be the what; people can click through to the PR for the how


# 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