Skip to content

fix(bigquery): support AI.FORECAST TVF parsing#7457

Merged
georgesittas merged 1 commit intotobymao:mainfrom
RedZapdos123:fix/bigquery-ai-forecast-tvf-parser
Apr 6, 2026
Merged

fix(bigquery): support AI.FORECAST TVF parsing#7457
georgesittas merged 1 commit intotobymao:mainfrom
RedZapdos123:fix/bigquery-ai-forecast-tvf-parser

Conversation

@RedZapdos123
Copy link
Copy Markdown
Contributor

@RedZapdos123 RedZapdos123 commented Apr 5, 2026

Summary:

This PR adds BigQuery parser/generator support for AI.FORECAST table valued function syntax.

The current main parses ML.FORECAST(...) but fails on documented AI.FORECAST(...) TVF forms with named arguments.

Resolves #7456.

Changes done:

  • Added a dedicated AIForecast expression:
    • sqlglot/expressions/functions.py
  • Added SQL generation for AIForecast:
    • sqlglot/generator.py
    • Preserves TABLE <name> prefix for table input, while keeping parenthesized query input unchanged.
  • Updated BigQuery FORECAST function parser routing:
    • sqlglot/parsers/bigquery.py
    • ML.FORECAST still uses existing ML parser path.
    • Non-ML FORECAST (for AI.FORECAST) now parses TVF first arg (TABLE <table> or (SELECT ...)) plus named args.
  • Added regression coverage:
    • tests/dialects/test_bigquery.py
    • New identity checks for:
      • AI.FORECAST(TABLE citibike_trips, data_col => 'num_trips', timestamp_col => 'date', horizon => 30)
      • AI.FORECAST((SELECT * FROM citibike_trips), data_col => 'num_trips', timestamp_col => 'date', horizon => 30)

Validation:

Executed in WSL:

python -m pytest -q tests/dialects/test_bigquery.py -k "ml_functions"

Result:

  • 1 passed, 57 deselected.

The screenshot of the focused test suite run, locally, on WSL for validation:

image

Ran the full test suite, locally on WSL for validation:

python -m pytest -q

Result:

  • 1074 passed in 57.76s.

The screenshot of the full test suite run, locally, on WSL for validation:

image

Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
Copy link
Copy Markdown
Collaborator

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

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

I think this can be cleaned up a bit, but I'll take it to the finish line. Thanks for the contribution!

@georgesittas georgesittas merged commit eb9dbac into tobymao:main Apr 6, 2026
18 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.

BigQuery: AI.FORECAST TVF syntax fails to parse

3 participants