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

fix(bigquery): escape table names with spaces for bigquery backend #9589

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions ibis/backends/bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,9 @@
self, name: str, database: str | None = None, schema: str | None = None
) -> ir.Table:
table_loc = self._warn_and_create_table_loc(database, schema)
table = sg.parse_one(f"`{name}`", into=sge.Table, read=self.name)

Check warning on line 551 in ibis/backends/bigquery/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/bigquery/__init__.py#L551

Added line #L551 was not covered by tests

table = sg.parse_one(name, into=sge.Table, read=self.name)

# Bigquery, unlike other bcakends, had existing support for specifying
# Bigquery, unlike other backends, had existing support for specifying
# table hierarchy in the table name, e.g. con.table("dataset.table_name")
# so here we have an extra layer of disambiguation to handle.

Expand Down Expand Up @@ -583,8 +582,6 @@

project, dataset = self._parse_project_and_dataset(database)

table = sg.parse_one(name, into=sge.Table, read=self.name)

bq_table = self.client.get_table(
bq.TableReference(
bq.DatasetReference(project=project, dataset_id=dataset),
Expand Down
11 changes: 11 additions & 0 deletions ibis/backends/bigquery/tests/system/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ def test_create_temp_table_from_scratch(project_id, dataset_id):
assert len(t.execute()) == 1


def test_create_table_from_scratch_with_spaces(project_id, dataset_id):
con = ibis.bigquery.connect(project_id=project_id, dataset_id=dataset_id)
name = f"{gen_name('bigquery_temp_table')} with spaces"
df = con.tables.functional_alltypes.limit(1)
t = con.create_table(name, obj=df)
try:
assert len(t.execute()) == 1
finally:
con.drop_table(name)


def test_table_suffix():
con = ibis.connect("bigquery://ibis-gbq")
t = con.table("gsod*", database="bigquery-public-data.noaa_gsod")
Expand Down