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

CREATE TABLE with OPTIONS throws ParseError for BigQuery dialect #1531

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

CREATE TABLE with OPTIONS throws ParseError for BigQuery dialect #1531

relud opened this issue May 3, 2023 · 2 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("CREATE TABLE t(x STRING) OPTIONS(table_expiration_days = 1)", 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 902, in _parse
    self.raise_error("Invalid expression / Unexpected token")
  File "/usr/local/lib/python3.10/site-packages/sqlglot/parser.py", line 945, in raise_error
    raise error
sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 1, Col: 33.
  CREATE TABLE t(x STRING) OPTIONS(table_expiration_days = 1)

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

Syntax

CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] TABLE [ IF NOT EXISTS ]
table_name
[(
  column | constraint_definition[, ...]
)]
[DEFAULT COLLATE collate_specification]
[PARTITION BY partition_expression]
[CLUSTER BY clustering_column_list]
[OPTIONS(table_option_list)]
[AS query_statement]
@relud
Copy link
Contributor Author

relud commented May 3, 2023

OPTIONS may also be used on individual columns

Fully reproducible code snippet

sqlglot.parse_one('CREATE TABLE t(x STRING OPTIONS(description = "x"))', 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 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 3176, in _parse_schema
    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: 32.
  CREATE TABLE t(x STRING OPTIONS(description = "x"))

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)]

@tobymao tobymao self-assigned this May 3, 2023
@tobymao tobymao closed this as completed in 9778c16 May 3, 2023
@tobymao
Copy link
Owner

tobymao commented May 3, 2023

thanks for the report, feel free to join our slack if you ever wanna discuss anything

https://tobikodata.com/slack

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