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

ParseError with OPTIONS inside STRUCT type for BigQuery dialect #1562

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

ParseError with OPTIONS inside STRUCT type for BigQuery dialect #1562

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

Comments

@relud
Copy link
Contributor

relud commented May 5, 2023

Before you file an issue

  • Make sure you specify the "read" dialect eg. parse_one(sql, read="spark")
  • Check if the issue still exists on main

Fully reproducible code snippet

sqlglot.parse_one('CREATE TABLE x(a STRUCT<b STRING OPTIONS (description = "b")>)', 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 164, 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 1041, in _parse_statement
    return self.STATEMENT_PARSERS[self._prev.token_type](self)
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 484, in <lambda>
    TokenType.CREATE: lambda self: self._parse_create(),
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 1134, in _parse_create
    this = self._parse_schema(this=table_parts)
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 3173, in _parse_schema
    args = self._parse_csv(
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 3983, in _parse_csv
    parse_result = parse_method()
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 3175, in <lambda>
    or self._parse_column_def(self._parse_field(any_token=True))
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 3181, in _parse_column_def
    kind = self._parse_types()
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 2843, in _parse_types
    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: 41.
  CREATE TABLE x(a STRUCT<b STRING OPTIONS (description = "b")>)

Official Documentation
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#column_name_and_column_schema

column :=
  column_name column_schema

column_schema :=
   {
     simple_type
     | STRUCT<field_list>
     | ARRAY<array_element_schema>
   }
   [PRIMARY KEY NOT ENFORCED | REFERENCES table_name(column_name) NOT ENFORCED]
   [DEFAULT default_expression]
   [NOT NULL]
   [OPTIONS(column_option_list)]

simple_type :=
  { data_type | STRING COLLATE collate_specification }

field_list :=
  field_name column_schema [, ...]

array_element_schema :=
  { simple_type | STRUCT<field_list> }
  [NOT NULL]
@tobymao tobymao self-assigned this May 6, 2023
@tobymao tobymao closed this as completed in 7b09bff May 6, 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