Skip to content

BigQuery: AI.FORECAST TVF syntax fails to parse #7456

@RedZapdos123

Description

@RedZapdos123

AI.FORECAST table-valued function syntax in BigQuery currently fails with a parser error when using documented named arguments.

The issue is reproducible in the latest main branch of SQLGlot.

Minimal reproducible example:

from sqlglot import parse_one

sql = 'SELECT * FROM AI.FORECAST(TABLE citibike_trips, data_col => "num_trips", timestamp_col => "date", horizon => 30)'
parse_one(sql, dialect="bigquery")

Actual behavior:

Raises:

sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 1, Col: 59.
  SELECT * FROM AI.FORECAST(TABLE citibike_trips, data_col => "num_trips", timestamp_col => "date", horizon => 30)

Expected behavior:

The query should parse successfully in BigQuery dialect and round-trip back to equivalent SQL.

Regression test (failing on current main):

A focused failing test case:

from tests.dialects.test_dialect import Validator

class TestBigQueryAIForecastIssue(Validator):
    dialect = "bigquery"

    def test_ai_forecast_tvf_parses(self):
        self.validate_identity(
            'SELECT * FROM AI.FORECAST(TABLE citibike_trips, data_col => "num_trips", timestamp_col => "date", horizon => 30)'
        )

The screenshot of the issue reproduction:

Image

Pytest command:

python -m pytest -q tests/dialects/test_bigquery_ai_forecast_issue.py -vv

Observed result: 1 failed, with the same parse error.

Reference

BigQuery docs:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions