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

feat(bigquery): add EXPORT DATA statement support #4688

Merged
merged 6 commits into from
Feb 3, 2025

Conversation

ArnoldHueteG
Copy link
Contributor

Add support for BigQuery's EXPORT DATA statement including:

  • WITH CONNECTION clause
  • OPTIONS clause
  • Query specification

@VaggelisD
Copy link
Collaborator

Hey @ArnoldHueteG, thank you for your contribution!

Could you please run make style and make unit locally to fix the CI issues?

sqlglot/dialects/bigquery.py Outdated Show resolved Hide resolved
sqlglot/expressions.py Outdated Show resolved Hide resolved
sqlglot/dialects/bigquery.py Outdated Show resolved Hide resolved
sqlglot/dialects/bigquery.py Outdated Show resolved Hide resolved
sqlglot/dialects/bigquery.py Outdated Show resolved Hide resolved
sqlglot/expressions.py Outdated Show resolved Hide resolved
sqlglot/tokens.py Show resolved Hide resolved
@ArnoldHueteG ArnoldHueteG force-pushed the bigquery-add-support-export branch from 5e34015 to 05fc102 Compare January 31, 2025 17:24
Comment on lines +494 to +497
ID_VAR_TOKENS = {
*parser.Parser.ID_VAR_TOKENS,
TokenType.EXPORT,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add this token in the base class' set instead of copying it here.

Comment on lines +848 to +860
parts = []
while True:
part = self._parse_var()
if not part:
break
parts.append(part.name)
if not self._match(TokenType.DOT):
break

if not parts:
self.raise_error("Expected connection name after WITH CONNECTION")

with_connection = exp.Identifier(this=".".join(parts))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's not parse the connection name manually here, consider using _parse_table_parts instead.

Comment on lines +862 to +867
if self._match_text_seq("OPTIONS"):
self._match(TokenType.L_PAREN)
options = self._parse_properties()
self._match(TokenType.R_PAREN)
else:
self.raise_error("Expected 'OPTIONS' after 'EXPORT DATA'")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should be able to clean this up using the OPTIONS property parser.

else:
self.raise_error("Expected 'OPTIONS' after 'EXPORT DATA'")

self._match_text_seq("AS")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self._match_text_seq("AS")
self._match(TokenType.ALIAS)

Comment on lines +871 to +875
# Parse the full SELECT statement
query = self._parse_statement()
if not isinstance(query, exp.Select):
self.raise_error("Expected SELECT statement in EXPORT DATA")

Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't have to do error handling like this, SQLGlot is intentionally lenient in these cases.

@VaggelisD
Copy link
Collaborator

Hey @ArnoldHueteG, thank you for the contribution & iterations, I have some bandwidth available so I'll drive this to the finish line.

@VaggelisD VaggelisD merged commit 9ea15c7 into tobymao:main Feb 3, 2025
7 checks passed
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.

4 participants