Skip to content

Commit 3c13d67

Browse files
authored
fix(athena): use exists instead of replace for create_database (#10767)
1 parent de0d29b commit 3c13d67

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

ibis/backends/athena/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,15 @@ def create_database(
449449
self, name: str, catalog: str | None = None, force: bool = False
450450
) -> None:
451451
name = sg.table(name, catalog=catalog, quoted=self.compiler.quoted)
452-
sql = sge.Create(this=name, kind="SCHEMA", replace=force)
452+
sql = sge.Create(this=name, kind="SCHEMA", exists=force)
453453
with self._safe_raw_sql(sql, unload=False):
454454
pass
455455

456456
def drop_database(
457457
self, name: str, catalog: str | None = None, force: bool = False
458458
) -> None:
459459
name = sg.table(name, catalog=catalog, quoted=self.compiler.quoted)
460-
sql = sge.Drop(this=name, kind="SCHEMA", replace=force)
460+
sql = sge.Drop(this=name, kind="SCHEMA", exists=force)
461461
with self._safe_raw_sql(sql, unload=False):
462462
pass
463463

ibis/backends/athena/tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,8 @@ def batting(self):
114114
@property
115115
def awards_players(self):
116116
return self._remap_column_names("awards_players")
117+
118+
119+
@pytest.fixture(scope="session")
120+
def con(tmp_path_factory, data_dir, worker_id):
121+
return TestConf.load_data(data_dir, tmp_path_factory, worker_id).connection
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
5+
from ibis.backends.tests.errors import PyAthenaOperationalError
6+
from ibis.util import gen_name
7+
8+
9+
def test_create_and_drop_database(con):
10+
name = gen_name("db")
11+
12+
# create it
13+
con.create_database(name)
14+
15+
# create it again with force=True (i.e., IF NOT EXISTS)
16+
con.create_database(name, force=True)
17+
18+
# create it again (should fail)
19+
with pytest.raises(PyAthenaOperationalError):
20+
con.create_database(name)
21+
22+
# drop it
23+
con.drop_database(name)
24+
25+
# drop it again with force=True (i.e., IF EXISTS)
26+
con.drop_database(name, force=True)
27+
28+
# drop it again (should fail)
29+
with pytest.raises(PyAthenaOperationalError):
30+
con.drop_database(name)

0 commit comments

Comments
 (0)