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

return default in get_column_values if no execute #386

Merged
merged 4 commits into from
Nov 11, 2021

Conversation

jmriego
Copy link
Contributor

@jmriego jmriego commented Jul 3, 2021

This is a:

  • bug fix PR with no breaking changes — please ensure the base branch is master
  • new functionality — please ensure the base branch is the latest dev/ branch
  • a breaking change — please ensure the base branch is the latest dev/ branch

Description & motivation

Fixes #304
I think get_column_values should return default if not executing.
The issue I'm describing is that this function has a default parameter that will be returned if no data is found. But if DBT is not on execution mode, it will return an empty string
https://github.com/fishtown-analytics/dbt-utils/blob/c8389533cc7f00823c50d08d904cdfa5f714ec8b/macros/sql/get_column_values.sql#L17

Using this simple code will trigger a warning as columns will default to an empty string if no execute:

{% set rep_types = dbt_utils.get_column_values(source_table, 'rep_type', default=[]) %}
{{ dbt_utils.surrogate_key(columns) }} AS row_hash

Checklist

  • I have verified that these changes work locally on the following warehouses (Note: it's okay if you do not have access to all warehouses, this helps us understand what has been covered)
    • BigQuery
    • Postgres
    • Redshift
    • Snowflake
  • I have "dispatched" any new macro(s) so non-core adapters can also use them (e.g. the star() source)
  • I have updated the README.md (if applicable)
  • I have added tests & descriptions to my models (and macros if applicable)
  • I have added an entry to CHANGELOG.md

@jasnonaz
Copy link
Contributor

This looks great!! Just adding one additional bit of logic as in the case someone doesn't specify default, we'd want to return an empty list rather than none.

@joellabes joellabes changed the base branch from main to next/patch November 11, 2021 01:55
@joellabes joellabes changed the base branch from next/patch to next/minor November 11, 2021 01:55
Copy link
Contributor

@joellabes joellabes left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @jmriego!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_column_values should return default if not executing
3 participants