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

fix(snowflake): COPY Subquery postfix #3449

Merged
merged 5 commits into from
May 10, 2024
Merged

Conversation

VaggelisD
Copy link
Collaborator

@VaggelisD VaggelisD commented May 10, 2024

Fixes #3434

This PR addresses the following issues:

  • COPY would only allow files in the FROM clause, extend it to allow subqueries as well

  • When parsing staged files such as @foo we'd also consume the following parentheses coming from (optional) staged file options such as SELECT * FROM @foo (FILE_FORMAT => ...). However, if there are no options specified we would end up consuming any following R_PAREN as well e.g. SELECT * FROM (SELECT * FROM @foo)

  • For transforming semi-structured data Snowflake specifies the subquery columns as [<alias>.]$<file_col_num>[.<element>]. However, the tokenizer always appends the TokenType.DOT to following a number e.g. $1.elem -> $1.e lem. To solve this issue, the tokenizer will only parse an integer (and not a real) if the number is prefixed by a token of type TokenType.PARAMETER

  • The base parser parses exp.Parameter as '[' <this> ':' <expression> ']' but only generates this. Snowflake parsers $<num> as exp.Parameter which can optionally be followed by a path & element name such as $1:a.c. For this reason, exp.Parameter now generates <this> [':' <expression>]

Docs

sqlglot/generator.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for addressing the comments 👍

@georgesittas georgesittas merged commit b76dfda into main May 10, 2024
6 checks passed
@georgesittas georgesittas deleted the vaggelisd/copy_postfix branch May 10, 2024 18:39
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

Successfully merging this pull request may close these issues.

Parsing issue for Snowflake COPY INTO queries with subqueries
3 participants