fix(bigquery): parse FOR SYSTEM TIME AS OF (with spaces) [CLAUDE]#7493
Open
lawrence3699 wants to merge 1 commit intotobymao:mainfrom
Open
fix(bigquery): parse FOR SYSTEM TIME AS OF (with spaces) [CLAUDE]#7493lawrence3699 wants to merge 1 commit intotobymao:mainfrom
lawrence3699 wants to merge 1 commit intotobymao:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Extends the BigQuery dialect tokenizer to recognize BigQuery’s alternative time-travel syntax FOR SYSTEM TIME AS OF (spaces instead of underscore), so it parses successfully and round-trips normalized output as FOR SYSTEM_TIME AS OF.
Changes:
- Added
FOR SYSTEM TIMEas an additional BigQuery keyword mapped toTokenType.TIMESTAMP_SNAPSHOT. - Added a BigQuery dialect identity test asserting parsing and normalization from
FOR SYSTEM TIME→FOR SYSTEM_TIME.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
sqlglot/dialects/bigquery.py |
Adds a multi-word keyword mapping so the tokenizer emits TIMESTAMP_SNAPSHOT for FOR SYSTEM TIME. |
tests/dialects/test_bigquery.py |
Adds coverage ensuring the spaced form parses and normalizes to the underscore form. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #7481
BigQuery accepts both
FOR SYSTEM_TIME AS OFandFOR SYSTEM TIME AS OF(with spaces instead of underscore). The parser only recognized the underscore form, raisingParseError: Invalid expression / Unexpected tokenfor the space form.Before:
SELECT * FROM tbl FOR SYSTEM TIME AS OF z→ ParseErrorAfter:
SELECT * FROM tbl FOR SYSTEM TIME AS OF z→ parses correctly, normalizes toFOR SYSTEM_TIME AS OFin outputThe fix adds
"FOR SYSTEM TIME"as an additional keyword mapping toTIMESTAMP_SNAPSHOTin the BigQuery tokenizer, alongside the existing"FOR SYSTEM_TIME"entry.Validation: BigQuery dialect tests pass (
python -m pytest tests/dialects/test_bigquery.py).