-
Notifications
You must be signed in to change notification settings - Fork 504
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
Add optional where clause to get_column_values #583
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this contribution, @epapineau !
Left a few small comments. I'd love to do two things:
- Move the
where
parameter to the end to avoid any possibility of breaking changes for anyone - Add an integration test to verify that it indeeds filters things as expected
Let me know if I can help with either!
@dbeatty10 made both requested updates~ Thanks again for your help |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integration test looks great! 🏅
Two small things to adjust in the changelog. Other than that, this looks good to go.
Co-authored-by: Doug Beatty <44704949+dbeatty10@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, Elise! ⭐
Thanks for your contribution to this issue! An awesome addition. I was just wondering how I could use the where parameter. I'm looking to get values from column A given column B is equal to a particular value. Here's my current macro based on your merge: {% macro get_green_columns(input_table) %}
{% set input_table=input_table %}
{% set green_columns=dbt_utils.get_column_values(table=ref('ref_all_green_columns'), column='column_name', where="table_name = '"~input_table~"'") %}
{{ return(green_columns) }}
{% endmacro %} Thanks for the help 😀 |
Hi @ed-muthiah 👋 Did the example you posted not work for you? It appeared to work as-is for me; see below. I created a seed named
And copied and pasted your macro into {% macro get_green_columns(input_table) %}
{% set input_table=input_table %}
{% set green_columns=dbt_utils.get_column_values(table=ref('ref_all_green_columns'), column='column_name', where="table_name = '"~input_table~"'") %}
{{ return(green_columns) }}
{% endmacro %} And then I created a file named {{ get_green_columns("green") }} Seeding and compiling using a terminal:
This yielded the following text in
|
Thanks, my issue was just a naming issue! Can confirm that your example above works. It would be great to add it to the readme as an example. |
@ed-muthiah I created this issue to add it to the readme as an example. |
Closes #511 closes #582
This is a:
All pull requests from community contributors should target the
main
branch (default).Description & motivation
Closes #511 & redundant #582. Adds a
where
clause parameter to theget_column_values
macro to enable filtering the returned columns.Checklist
star()
source)limit_zero()
macro in place of the literal string:limit 0
dbt_utils.type_*
macros instead of explicit datatypes (e.g.dbt_utils.type_timestamp()
instead ofTIMESTAMP