Skip to content

fix(bigquery): parse FOR SYSTEM TIME AS OF (with spaces) [CLAUDE]#7493

Open
lawrence3699 wants to merge 1 commit intotobymao:mainfrom
lawrence3699:fix/bigquery-system-time-spaces
Open

fix(bigquery): parse FOR SYSTEM TIME AS OF (with spaces) [CLAUDE]#7493
lawrence3699 wants to merge 1 commit intotobymao:mainfrom
lawrence3699:fix/bigquery-system-time-spaces

Conversation

@lawrence3699
Copy link
Copy Markdown

Closes #7481

BigQuery accepts both FOR SYSTEM_TIME AS OF and FOR SYSTEM TIME AS OF (with spaces instead of underscore). The parser only recognized the underscore form, raising ParseError: Invalid expression / Unexpected token for the space form.

Before: SELECT * FROM tbl FOR SYSTEM TIME AS OF z → ParseError
After: SELECT * FROM tbl FOR SYSTEM TIME AS OF z → parses correctly, normalizes to FOR SYSTEM_TIME AS OF in output

The fix adds "FOR SYSTEM TIME" as an additional keyword mapping to TIMESTAMP_SNAPSHOT in the BigQuery tokenizer, alongside the existing "FOR SYSTEM_TIME" entry.

Validation: BigQuery dialect tests pass (python -m pytest tests/dialects/test_bigquery.py).

Copilot AI review requested due to automatic review settings April 12, 2026 16:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 TIME as an additional BigQuery keyword mapped to TokenType.TIMESTAMP_SNAPSHOT.
  • Added a BigQuery dialect identity test asserting parsing and normalization from FOR SYSTEM TIMEFOR 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.

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.

BigQuery: FOR SYSTEM TIME AS OF not parsed in BigQuery dialect

2 participants