-
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
dbt_utils.get_column_values should use the Relation object it's given instead of making its own #424
Comments
Additional context is that we discovered this issue when trying to install |
Hi @fivetran-joemarkiewicz and @morgankrey-amplitude, thanks for opening this! From a cursory glance at As for |
Hey @joellabes fun seeing you on the dbt-labs side! 🎉 Thanks for taking a look over this. I'll try setting the |
Hey @joellabes after @fivetran-joemarkiewicz and I sat down to debug for a while, it seems that there's a general issue with quoting permutations in First, we confirmed that our explicitly-lowercased table is queriable from Snowflake natively Next, we confirmed that we can query the table as a source directly, successfully Finally, we confirmed that querying the source using Our quoting setup in our YAML file is below @fivetran-joemarkiewicz please feel free to add any context you think I missed! |
Hey @morgankrey-amplitude, thanks for the writeup - were these issues after trying the patch I described above?
You can try locally by making a copy of the macro and referencing it without a |
Hey @joellabes I tried this locally but it didn't seem to do the trick. Although, I may have not done this correctly at all! Please excuse my noviceness, but I updated the macro locally to set {%- set target_relation = table) -%} However, @morgankrey-amplitude would you be able to try this on your end as well as your warehouse has the mixed casing and mine doesn't? You can copy the below as a new macro and like @joellabes said you could just reference the macro name without ## Named get_column_values.sql
{% macro get_column_values(table, column, order_by='count(*) desc', max_records=none, default=none) -%}
{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
{%- if not execute -%}
{{ return('') }}
{% endif %}
{%- set target_relation = table -%}
{%- call statement('get_column_values', fetch_result=true) %}
{%- if not target_relation and default is none -%}
{{ exceptions.raise_compiler_error("In get_column_values(): relation " ~ table ~ " does not exist and no default value was provided.") }}
{%- elif not target_relation and default is not none -%}
{{ log("Relation " ~ table ~ " does not exist. Returning the default value: " ~ default) }}
{{ return(default) }}
{%- else -%}
select
{{ column }} as value
from {{ target_relation }}
group by {{ column }}
order by {{ order_by }}
{% if max_records is not none %}
limit {{ max_records }}
{% endif %}
{% endif %}
{%- endcall -%}
{%- set value_list = load_result('get_column_values') -%}
{%- if value_list and value_list['data'] -%}
{%- set values = value_list['data'] | map(attribute=0) | list %}
{{ return(values) }}
{%- else -%}
{{ return(default) }}
{%- endif -%}
{%- endmacro %} and then in your query you would use the below. {%- set old_formula_fields = get_column_values(source('salesforce', 'fivetran_formula'),'field') | upper -%}
select
{{ dbt_utils.star(source('salesforce','test_order_c'), except=old_formula_fields) }}
from {{ source('salesforce', 'test_order_c') }} @joellabes feel free to call out if this is not what you were referring to 😄 |
Interestingly, it's at least a different error! Once I replaced my code with what you had above @fivetran-joemarkiewicz, I got the following Quoting the "field" reference, since the |
OK! This is good news. I infer that you've got the Could you remove that upper filter, and check whether you're getting results back from the get_column_values macro? You should be able to log them by just putting If you are, then we have the solution for this original bug - update the macro to use the From there, assuming that the output is lowercase, we just need to work out a way to uppercase them without breaking the introspective query. Worst case we can do a loop, but there should be a tidier way than that. |
@morgankrey-amplitude sorry for the delay in getting back to you! I've done some experimentation today, and I have a couple of approaches that should work. Option 1 (my preference): you should just be able to wrap the get_column_values call in another set of parens.
Option 2: (pretty much guaranteed to work, but a bit ugly): just set uppercase them separately
Let me know how you get on with those |
At this point @joellabes I think everything is working! The issue now is pulling this knowledge into the salesforce formula package from Fivetran that I think @fivetran-joemarkiewicz and I need to figure out from here. I've confirmed that I am able to get all the column values in lower, upper, and original casing using this modified macro and macro call above |
Thanks so much @joellabes. I agree with @morgankrey-amplitude that we should move this back to the @morgankrey-amplitude I just opened an issue on the formula_utils package so we may take this issue back to the package. Thanks again @joellabes 🎉 |
Yay glad to hear it! In addition to any chances on the formula_utils side, there's definitely a bug on dbt_utils' side around that artisinal, handcrafted |
Describe the bug
The
get_column_values
andstar
macros do not seem to properly work when the source is passed through as an argument and thesrc.yml
is leveraging the non-default quoting. Specifically for Snowflake.Steps to reproduce
Use quoting in your
src.yml
:With the above
src.yml
config if I attempt to use theget_column_values
andstar
macro like below:The resulting compiled output is completely empty.
Expected results
If I remove the quoting config in the
src.yml
then I see the output as expected. The expected results would be to allow users that have to use the quoting config to still be able to use the combination of these macros.Actual results
Compiled output below.
Screenshots and log output
System information
The contents of your
packages.yml
file:Which database are you using dbt with?
The output of
dbt --version
:Additional context
Are you interested in contributing the fix?
I would be happy to contribute to this fix! However, I am not entirely sure where the issue is arising? Once we locate, I would be happy to help in any way I can!
The text was updated successfully, but these errors were encountered: