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

json_extract should use double quotes on Snowflake #103

Open
LewisDavies opened this issue Mar 17, 2023 · 2 comments
Open

json_extract should use double quotes on Snowflake #103

LewisDavies opened this issue Mar 17, 2023 · 2 comments

Comments

@LewisDavies
Copy link

LewisDavies commented Mar 17, 2023

I'm using the Stripe package and have set project variables for fields I want to extract from metadata columns. It works on most values but isn't extracting anything when the key contains a full stop, e.g. plan.id.

I have fixed this locally by adding double quotes to the Snowflake macro:

{% macro snowflake__json_extract(string, string_path) %}

  json_extract_path_text(try_parse_json( {{string}} ), {{ "'\"" ~ string_path ~ "\"'" }} )

{% endmacro %}

Happy to make a PR but I'm not sure whether the problem applies to other databases.

@LewisDavies LewisDavies changed the title json_extract should used double quotes on Snowflake json_extract should use double quotes on Snowflake Mar 17, 2023
@fivetran-joemarkiewicz
Copy link
Contributor

Hi @LewisDavies thanks so much for opening this issue and sharing the root of the issue and a potential fix. That is interesting that the full stop breaks the macro, but your suggestion seems to make sense to me. I agree with you that I would want to validate the fix on the other platforms as well if we were to roll this fix out in a future release.

Would you mind sharing the original error message (and possibly the compiled snippet where this breaks), and then the equivalent when using this suggested version of the macro and seeing the what the compiled output is and how it succeeds? In the meantime, I will explore recreating the issue with the other platforms and attempt a similar solution.

@LewisDavies
Copy link
Author

There's isn't actually an error message, it just returns null. In Snowflake you can access JSON values with dot notation, so without quotes the function is looking for the id field in the plan object.

I suppose my suggested changes could be breaking if some people are using dot notation in their scripts. Fortunately there are other ways of accessing values though.

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

No branches or pull requests

2 participants