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(snowflake): add support for // comments #1765

Merged
merged 1 commit into from
Jun 13, 2023
Merged

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Jun 13, 2023

Fixes #1763

This also fixes a tokenizer bug related to Jinja comments ({# ... #}). In some dialects we've overridden the COMMENTS tokenizer list, excluding these delimiters, but we actually want to recognize them in all dialects.

Current behavior (note that BigQuery uses # as a comment delimiter):

>>> from sqlglot.dialects import BigQuery
>>> for tok in BigQuery.Tokenizer().tokenize("SELECT 1 {# this is a comment #}"):
...     print(tok)
...
<Token token_type: TokenType.SELECT, text: SELECT, line: 1, col: 6, start: 0, end: 5, comments: []>
<Token token_type: TokenType.NUMBER, text: 1, line: 1, col: 8, start: 7, end: 7, comments: []>
<Token token_type: TokenType.L_BRACE, text: {, line: 1, col: 10, start: 9, end: 9, comments: [' this is a comment #}']>

With the fix introduced in this PR:

>>> from sqlglot.dialects import BigQuery
>>> for tok in BigQuery.Tokenizer().tokenize("SELECT 1 {# this is a comment #}"):
...     print(tok)
...
<Token token_type: TokenType.SELECT, text: SELECT, line: 1, col: 6, start: 0, end: 5, comments: []>
<Token token_type: TokenType.NUMBER, text: 1, line: 1, col: 8, start: 7, end: 7, comments: [' this is a comment ']>

@tobymao tobymao merged commit 6cfc873 into main Jun 13, 2023
@tobymao tobymao deleted the jo/snowflake_comments branch June 13, 2023 15:27
adrianisk pushed a commit to adrianisk/sqlglot that referenced this pull request Jun 21, 2023
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.

Comments starting with // throws a ParseError in Snowflake ❄️
2 participants