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

Snowflake Semi Structured Data incompatibility #965

Closed
sercandogan opened this issue Sep 13, 2022 · 4 comments
Closed

Snowflake Semi Structured Data incompatibility #965

sercandogan opened this issue Sep 13, 2022 · 4 comments
Labels

Comments

@sercandogan
Copy link

Hey 🙌🏽,

Snowflake supports semi-structured data as variant type and you can access the item by using colon and dot.
Please see: https://docs.snowflake.com/en/user-guide/querying-semistructured.html#traversing-semi-structured-data

Example below fails with unexpected argument named:

from sometable
filter json:first_key.second_key == 1 and json:third_key == 50

I see also : used for named args & parameters. How can we support this syntax?

@max-sixty
Copy link
Member

max-sixty commented Sep 13, 2022

Thanks for the issue @sercandogan

Generally we'd use an s-string for features that PRQL doesn't yet support, like:

from sometable
filter s"json:first_key.second_key" == 1 and s"json:third_key" == 50

Unfortunately this specific case is more difficult — because : is non-standard in SQL, and PRQL runs a formatter over the SQL, we get:

SELECT
  sometable.*
FROM
  sometable
WHERE
  json :first_key.second_key = 1
  AND json :third_key = 50

Note the space in json :first_key. Am I correct that snowflake doesn't like the space? Or is it OK?

We've had this issue a couple of times around s-strings. Ideally we could not format the SQL inside s-strings, but we'd need to think of how to do this — maybe we pass a string with a sentinel and then replace it after the formatting. (We do want to do some formatting, because otherwise it's a very long line, and producing interpretable SQL is a core principle)

@mklopets
Copy link
Collaborator

Non-ideal but we used to have a similar issue and we worked around it by just always running a regex replacement to remove these spaces automatically straight after compilation to SQL: s/json :/json:/g

@max-sixty max-sixty changed the title Snowflake Semi Structured Data incompatibility Avoiding auto-sql-formatting (nee snowflake structured data) Dec 17, 2022
@max-sixty max-sixty changed the title Avoiding auto-sql-formatting (nee snowflake structured data) Snowflake Semi Structured Data incompatibility Dec 17, 2022
@max-sixty
Copy link
Member

I opened #1284 to address the broader issue around formatting, which subsumes this issue, so I'll close this.

@max-sixty
Copy link
Member

max-sixty commented Sep 6, 2024

(in case anyone returns to this issue, the updated query above is

from sometable
filter s"json:first_key.second_key" == 1 && s"json:first_key.second_key" == 1

...which complies to...

SELECT
  *
FROM
  sometable
WHERE
  json :first_key.second_key = 1
  AND json :first_key.second_key = 1

-- Generated by PRQL compiler version:0.13.0 (https://prql-lang.org)

...and shouldn't insert a space in json:first_key.second_key

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

No branches or pull requests

3 participants