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

[Issue] get_column_values now only accepts a relation #153

Closed
3 tasks done
clrcrl opened this issue Jul 26, 2019 · 2 comments · Fixed by #154
Closed
3 tasks done

[Issue] get_column_values now only accepts a relation #153

clrcrl opened this issue Jul 26, 2019 · 2 comments · Fixed by #154

Comments

@clrcrl
Copy link
Contributor

clrcrl commented Jul 26, 2019

Steps to reproduce

  1. Install dbt-utils v0.2.1
  2. Call get_column_values with a string table reference
{{ dbt_utils.get_column_values(
    table="raw_jaffle_shop.customers",
    column='first_name',
    max_records=50
) }}

Expected results

  • Macro compiles correctly (this was the behaviour <0.2.1)

Actual results

Running with dbt=0.14.0
Found 10 models, 28 tests, 0 snapshots, 0 analyses, 249 macros, 0 operations, 0 seed files, 3 sources

16:53:00 | Concurrency: 1 threads (target='dev')
16:53:00 |
Encountered an error:
Runtime Error
  Compilation Error in macro get_column_values (macros/sql/get_column_values.sql)
    'str object' has no attribute 'database'

Commentary

Prior to v0.2.1, you could pass get_column_values a table like this my_schema.my_table.

However #152 now means you need to pass the macro a relation instead. All of these are valid:

{{ dbt_utils.get_column_values(
    table=ref('stg_jaffle_shop__customers'),
    column='first_name',
    max_records=50
) }}
{{ dbt_utils.get_column_values(
    table=source('raw_jaffle_shop', 'customers'),
    column='first_name',
    max_records=50
) }}
{%- set source_relation = adapter.get_relation(
      database=target.database,
      schema='raw_jaffle_shop',
      identifier="customers") -%}

{{ dbt_utils.get_column_values(
    table=source_relation,
    column='first_name',
    max_records=50
) }}

I'm totally 100% behind this change, but there needs to be some cleaning up here to communicate it.

  • The README.md still says shows an example of passing a hardcoded table reference in the pivot example
  • Techhhhhnically we should replace the table argument name with relation, but that's likely going to break things (on the fence about whether we should fix it)
  • There's also a little bit of redundant code in get_column_values which would be good to clean up:
    {%- set target_relation = adapter.get_relation(database=table.database,
                                          schema=table.schema,
                                         identifier=table.identifier) -%}

can be replaced with

    {%- set target_relation = table -%}
@clrcrl
Copy link
Contributor Author

clrcrl commented Jul 26, 2019

@emilieschario – I'm happy to fix this, but also happy for you to take this one :)

@emilieschario
Copy link
Contributor

Thanks so much for taking this @clrcrl! I was traveling this weekend!

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 a pull request may close this issue.

2 participants