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 support #99

Closed
danfrankj opened this issue Apr 21, 2022 · 7 comments
Closed

Snowflake Semi-structured data support #99

danfrankj opened this issue Apr 21, 2022 · 7 comments

Comments

@danfrankj
Copy link

I believe this would be a bigger change than simply adding a new dialect as new parsing is required for json extraction syntax

Test Cases

SELECT foo:bar

SELECT foo:bar:baz::DATE

SELECT foo:bar[0]

SELECT foo:bar.baz

Ref:
https://docs.snowflake.com/en/user-guide/querying-semistructured.html#traversing-semi-structured-data

@tobymao
Copy link
Owner

tobymao commented Apr 21, 2022

this is not too difficult, just need to support single semicolon, if you want to take a stab at this, i can walk you through what needs to be done. can do a vid call or some kind of chat app to sync if you're interested.

i'm not familiar with snowflake, but is x:y just JSON_PATH(x, y) or STRUCT_EXTRACT?, seems more similar to struct_extract...

@tobymao
Copy link
Owner

tobymao commented Apr 21, 2022

@danfrankj i'm reading through snowflake docs and i don't quite understand the difference between : and .

can i just convert : -> .? this is a one line change

diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 117b0c9..7edb4a8 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -1103,7 +1103,7 @@ class Parser:
             this = self.expression(exp.Column, this=this)
         this = self._parse_bracket(this)
 
-        while self._match(TokenType.DOT):
+        while self._match_set({TokenType.DOT, TokenType.COLON}):
             field = self._parse_id_var() or self._parse_star()
             if isinstance(this, exp.Column) and not this.table:
                 this = self.expression(exp.Column, this=field, table=this.this)

@NodeJSmith
Copy link

@tobymao I know this is closed, but I'm hitting the same issue currently with version 10.5.10. Happy to provide more information and/or to open a new issue for this. Below is a screenshot of the issue - I imagine it's because there are double quotes, since that is what seems to differ between my example and the example provided by @danfrankj

image

@tobymao
Copy link
Owner

tobymao commented Jan 29, 2023

please open a new issue thanks!

@tobymao
Copy link
Owner

tobymao commented Jan 30, 2023

@NodeJSmith i tried to recreate your error from your screen shot but it seems to work

python -m sqlglot 'select generated_features:"uws.rcu"' --read=snowflake
SELECT
  "generated_features"['uws.rcu']

@tobymao
Copy link
Owner

tobymao commented Jan 30, 2023

don't forget to pass the read dialect in as snowflake

@NodeJSmith
Copy link

@tobymao fudge, I totally forgot to do that 🤦‍♀️ I'll try it today, I imagine that will fix it. Sorry for the false alarm

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

3 participants