Skip to content

Commit

Permalink
fix(pyspark): generate IF NOT EXISTS if force=True (#10782)
Browse files Browse the repository at this point in the history
Co-authored-by: Phillip Cloud <[email protected]>
  • Loading branch information
gforsyth and cpcloud authored Feb 4, 2025
1 parent 3e86e2d commit c7d1d38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ibis/backends/pyspark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def create_database(

sql = sge.Create(
kind="DATABASE",
exist=force,
exists=force,
this=sg.to_identifier(name, quoted=self.compiler.quoted),
properties=properties,
)
Expand All @@ -533,7 +533,7 @@ def drop_database(
"""
sql = sge.Drop(
kind="DATABASE",
exist=force,
exists=force,
this=sg.to_identifier(name, quoted=self.compiler.quoted),
cascade=force,
)
Expand Down
33 changes: 33 additions & 0 deletions ibis/backends/pyspark/tests/test_ddl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import ibis
from ibis import util
from ibis.backends.tests.errors import PySparkAnalysisException
from ibis.tests.util import assert_equal

pyspark = pytest.importorskip("pyspark")
Expand Down Expand Up @@ -177,3 +178,35 @@ def test_create_table_reserved_identifier(con, alltypes, keyword_t):
t = con.create_table(keyword_t, expr)
result = t.count().execute()
assert result == expected


@pytest.mark.xfail_version(
pyspark=["pyspark<3.5"],
raises=ValueError,
reason="PySparkAnalysisException is not available in PySpark <3.5",
)
def test_create_database_exists(con):
con.create_database(dbname := util.gen_name("dbname"))

with pytest.raises(PySparkAnalysisException):
con.create_database(dbname)

con.create_database(dbname, force=True)

con.drop_database(dbname, force=True)


@pytest.mark.xfail_version(
pyspark=["pyspark<3.5"],
raises=ValueError,
reason="PySparkAnalysisException is not available in PySpark <3.5",
)
def test_drop_database_exists(con):
con.create_database(dbname := util.gen_name("dbname"))

con.drop_database(dbname)

with pytest.raises(PySparkAnalysisException):
con.drop_database(dbname)

con.drop_database(dbname, force=True)

0 comments on commit c7d1d38

Please sign in to comment.