Skip to content

Commit

Permalink
return default in get_column_values if no execute (dbt-labs#386)
Browse files Browse the repository at this point in the history
* return default in get_column_values if no execute

* Update CHANGELOG.md

* Update macros/sql/get_column_values.sql

Co-authored-by: Jason Ganz <[email protected]>

* Update require-dbt-version

Co-authored-by: Joel Labes <[email protected]>
Co-authored-by: Jason Ganz <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2021
1 parent 296de1f commit 2ed471b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ If you were relying on the position to match up your optional arguments, this ma
## Under the hood
* Update the default implementation of concat macro to use `||` operator ([#373](https://github.com/fishtown-analytics/dbt-utils/pull/314) from [@ChristopheDuong](https://github.com/ChristopheDuong)). Note this may be a breaking change for adapters that support `concat()` but not `||`, such as Apache Spark.
- Use `power()` instead of `pow()` in `generate_series()` and `haversine_distance()` as they are synonyms in most SQL dialects, but some dialects only have `power()` ([#354](https://github.com/fishtown-analytics/dbt-utils/pull/354) from [@swanderz](https://github.com/swanderz))
- Make `get_column_values` return the default value passed as a parameter instead of an empty string before compilation ([#304](https://github.com/dbt-labs/dbt-utils/pull/386) from [@jmriego](https://github.com/jmriego)

# dbt-utils v0.6.6

Expand Down
6 changes: 4 additions & 2 deletions macros/sql/get_column_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
{% endmacro %}

{% macro default__get_column_values(table, column, order_by='count(*) desc', max_records=none, default=none) -%}

{% if default is none %}
{% set default = [] %}
{% endif %}
{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
{%- if not execute -%}
{{ return('') }}
{{ return(default) }}
{% endif %}

{%- set target_relation = adapter.get_relation(database=table.database,
Expand Down

0 comments on commit 2ed471b

Please sign in to comment.