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

UNNEST(ARRAY<...>[]) throws ParseError for BigQuery dialect #1532

Closed
relud opened this issue May 3, 2023 · 0 comments
Closed

UNNEST(ARRAY<...>[]) throws ParseError for BigQuery dialect #1532

relud opened this issue May 3, 2023 · 0 comments
Assignees

Comments

@relud
Copy link
Contributor

relud commented May 3, 2023

observed on both version 11.7.1 and commit e7111ba6afdb67ae7be52cf39384d7bcb86a8dac

Fully reproducible code snippet

sqlglot.parse_one("SELECT * FROM UNNEST(ARRAY<STRUCT<x INT64>>[])", read="bigquery")

traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/sqlglot/__init__.py", line 150, in parse_one
    result = dialect.parse(sql, **opts)
  File "/usr/local/lib/python3.10/site-packages/sqlglot/dialects/dialect.py", line 163, in parse
    return self.parser(**opts).parse(self.tokenize(sql), sql)
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 836, in parse
    return self._parse(
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 899, in _parse
    expressions.append(parse_method(self))
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 1047, in _parse_statement
    expression = self._parse_set_operations(expression) if expression else self._parse_select()
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 1840, in _parse_select
    from_ = self._parse_from()
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 1986, in _parse_from
    exp.From, comments=self._prev_comments, expressions=self._parse_csv(self._parse_table)
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 3974, in _parse_csv
    parse_result = parse_method()
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 2234, in _parse_table
    unnest = self._parse_unnest()
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 2287, in _parse_unnest
    expressions = self._parse_wrapped_csv(self._parse_column)
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 4008, in _parse_wrapped_csv
    return self._parse_wrapped(lambda: self._parse_csv(parse_method, sep=sep))
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 4013, in _parse_wrapped
    self._match_r_paren()
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 4389, in _match_r_paren
    self.raise_error("Expecting )")
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 945, in raise_error
    raise error
sqlglot.errors.ParseError: Expecting ). Line 1, Col: 28.
  SELECT * FROM UNNEST(ARRAY<STRUCT<x INT64>>[])

Official Documentation
https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#unnest_and_structs

example:

SELECT *
FROM UNNEST(
  ARRAY<
    STRUCT<
      x INT64,
      y STRING,
      z STRUCT<a INT64, b INT64>>>[
        (1, 'foo', (10, 11)),
        (3, 'bar', (20, 21))]);

/*---+-----+----------*
 | x | y   | z        |
 +---+-----+----------+
 | 1 | foo | {10, 11} |
 | 3 | bar | {20, 21} |
 *---+-----+----------*/
@tobymao tobymao self-assigned this May 3, 2023
@tobymao tobymao closed this as completed in 19c0490 May 4, 2023
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

2 participants