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

Highlight in error is off by one for BigQuery when identifiers are quoted #1677

Closed
maureen-daum opened this issue May 23, 2023 · 2 comments
Closed
Assignees

Comments

@maureen-daum
Copy link
Contributor

When trying to parse a BigQuery statement that has an error, the returned error info's start_context and highlight are off by one when the query quotes the identifiers.

Fully reproducible code snippet

import sqlglot

sql = "SELECT * FROM `TableA` UNION `TableB`"
try:
    parse = sqlglot.parse_one(sql, read="bigquery")
except Exception as e:
    error = e.errors[0]
    print(f'With quotes: Start context: {error["start_context"]}; Highlight: {error["highlight"]}')


sql = "SELECT * FROM TableA UNION TableB"
try:
    parse = sqlglot.parse_one(sql, read="bigquery")
except Exception as e:
    error = e.errors[0]
    print(f'Without quotes: Start context: {error["start_context"]}; Highlight: {error["highlight"]}')

Expected output:

With quotes: Start context: SELECT * FROM TableA UNION ; Highlight: TableB
Without quotes: Start context: SELECT * FROM TableA UNION ; Highlight: TableB

Actual output:

With quotes: Start context: SELECT * FROM `TableA` UNION `T; Highlight: ableB`
Without quotes: Start context: SELECT * FROM TableA UNION ; Highlight: TableB
@georgesittas
Copy link
Collaborator

georgesittas commented May 23, 2023

I'm looking into this, see also #1673 (comment).

EDIT: seems like this is an unrelated issue, although (coincidentally!) also an off by one error! Thanks for the report.

@maureen-daum
Copy link
Contributor Author

Thanks!

adrianisk pushed a commit to adrianisk/sqlglot that referenced this issue 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

No branches or pull requests

3 participants