bug: bigquery backend fails for tables with spaces in table name
akanz1 opened this issue · comments
What happened?
Executing connection.table()
with a table name which contains spaces fails on the bigquery backend. This backend seems to be a bit of a special case overriding the table
method defined in /sql/__init__.py
.
Minimal example
This fails:
connector.con.table("table name with spaces")
Traceback (most recent call last):
File "/Users/.../code/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 1300, in parse_into
return self._parse(parser, raw_tokens, sql)
File "/Users/.../code/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 1342, in _parse
self.raise_error("Invalid expression / Unexpected token")
File "/Users/.../code/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 1383, in raise_error
raise error
sqlglot.errors.ParseError: Invalid expression / Unexpected token. Line 1, Col: 10.
table name with spaces
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/.../code/src/platform/data_connectors/tests/connectors/test_bigquery.py", line 73, in <module>
connector.con.table("table name with spaces")
File "/Users/.../code/.venv/lib/python3.10/site-packages/ibis/backends/bigquery/__init__.py", line 551, in table
table = sg.parse_one(name, into=sge.Table, read=self.name)
File "/Users/.../code/.venv/lib/python3.10/site-packages/sqlglot/__init__.py", line 134, in parse_one
result = dialect.parse_into(into, sql, **opts)
File "/Users/.../code/.venv/lib/python3.10/site-packages/sqlglot/dialects/dialect.py", line 535, in parse_into
return self.parser(**opts).parse_into(expression_type, self.tokenize(sql), sql)
File "/Users/.../code/.venv/lib/python3.10/site-packages/sqlglot/parser.py", line 1305, in parse_into
raise ParseError(
sqlglot.errors.ParseError: Failed to parse 'table name with spaces' into <class 'sqlglot.expressions.Table'>
while the following passes:
connector.con.table("`table name with spaces`")
I would expect bigquery to behave consistently to other backends, therefore not requiring any manual escaping outside ibis to make things work.
What version of ibis are you using?
9.1.0
What backend(s) are you using, if any?
Bigquery
Relevant log output
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
For context: https://cloud.google.com/bigquery/docs/tables#table_naming
When you create a table in BigQuery, the table name must be unique per dataset. The table name can:
Contain characters with a total of up to 1,024 UTF-8 bytes.
Contain Unicode characters in category L (letter), M (mark), N (number), Pc (connector, including underscore), Pd (dash), Zs (space). For more information, see General Category.
The following are all examples of valid table names: table 01, ग्राहक, 00_お客様, étudiant-01.
Unicode table names launch October 14, 2020. https://cloud.google.com/bigquery/docs/release-notes?hl=en#October_14_2020