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(pyspark): generate IF NOT EXISTS if force=True #10782

Merged
merged 2 commits into from
Feb 4, 2025
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
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

Check warning on line 12 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L12

Added line #L12 was not covered by tests
from ibis.tests.util import assert_equal

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


@pytest.mark.xfail_version(

Check warning on line 183 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L183

Added line #L183 was not covered by tests
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"))

Check warning on line 189 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L188-L189

Added lines #L188 - L189 were not covered by tests

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

Check warning on line 192 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L191-L192

Added lines #L191 - L192 were not covered by tests

con.create_database(dbname, force=True)

Check warning on line 194 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L194

Added line #L194 was not covered by tests

con.drop_database(dbname, force=True)

Check warning on line 196 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L196

Added line #L196 was not covered by tests


@pytest.mark.xfail_version(

Check warning on line 199 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L199

Added line #L199 was not covered by tests
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"))

Check warning on line 205 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L204-L205

Added lines #L204 - L205 were not covered by tests

con.drop_database(dbname)

Check warning on line 207 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L207

Added line #L207 was not covered by tests

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

Check warning on line 210 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L209-L210

Added lines #L209 - L210 were not covered by tests

con.drop_database(dbname, force=True)

Check warning on line 212 in ibis/backends/pyspark/tests/test_ddl.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/pyspark/tests/test_ddl.py#L212

Added line #L212 was not covered by tests