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(duckdb): fix create_table() in databases with spaces in the name #9817

Merged
merged 1 commit into from
Aug 26, 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
2 changes: 1 addition & 1 deletion ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def create_table(
schema = obj.schema()

this = sge.Schema(
this=sg.table(name, db=database),
this=sg.table(name, db=database, quoted=self.compiler.quoted),
expressions=[
sge.ColumnDef(
this=sg.to_identifier(name, quoted=self.compiler.quoted),
Expand Down
12 changes: 4 additions & 8 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@ def create_table(
else:
temp_name = name

initial_table = sge.Table(
this=sg.to_identifier(temp_name, quoted=self.compiler.quoted),
catalog=catalog,
db=database,
initial_table = sg.table(
temp_name, catalog=catalog, db=database, quoted=self.compiler.quoted
)
target = sge.Schema(this=initial_table, expressions=column_defs)

Expand All @@ -201,10 +199,8 @@ def create_table(
)

# This is the same table as initial_table unless overwrite == True
final_table = sge.Table(
this=sg.to_identifier(name, quoted=self.compiler.quoted),
catalog=catalog,
db=database,
final_table = sg.table(
name, catalog=catalog, db=database, quoted=self.compiler.quoted
)
with self._safe_raw_sql(create_stmt) as cur:
if query is not None:
Expand Down
14 changes: 14 additions & 0 deletions ibis/backends/duckdb/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,20 @@
assert "ork" not in default_memory_db.list_tables()


@pytest.mark.parametrize(

Check warning on line 329 in ibis/backends/duckdb/tests/test_client.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/duckdb/tests/test_client.py#L329

Added line #L329 was not covered by tests
"database_file",
[
"with spaces.ddb",
"space catalog.duckdb.db",
],
)
def test_create_table_quoting(database_file, tmp_path):
conn = ibis.duckdb.connect(tmp_path / database_file)
t = conn.create_table("t", {"a": [0, 1, 2]})
result = set(conn.execute(t.a))
assert result == {0, 1, 2}

Check warning on line 340 in ibis/backends/duckdb/tests/test_client.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/duckdb/tests/test_client.py#L337-L340

Added lines #L337 - L340 were not covered by tests


@pytest.mark.parametrize(
("url", "method_name"),
[
Expand Down