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(oracle): implement current_catalog and current_database correctly #9918

Merged
merged 4 commits 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
10 changes: 0 additions & 10 deletions ibis/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,6 @@ def list_catalogs(self, like: str | None = None) -> list[str]:

"""

@property
@abc.abstractmethod
def current_catalog(self) -> str:
"""The current catalog in use."""


class CanCreateCatalog(CanListCatalog):
@abc.abstractmethod
Expand Down Expand Up @@ -706,11 +701,6 @@ def list_databases(

"""

@property
@abc.abstractmethod
def current_database(self) -> str:
"""The current database in use."""


class CanCreateDatabase(CanListDatabase):
@abc.abstractmethod
Expand Down
8 changes: 0 additions & 8 deletions ibis/backends/datafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,6 @@ def raw_sql(self, query: str | sge.Expression) -> Any:
self._log(query)
return self.con.sql(query)

@property
def current_catalog(self) -> str:
raise NotImplementedError()

@property
def current_database(self) -> str:
raise NotImplementedError()

def list_catalogs(self, like: str | None = None) -> list[str]:
code = (
sg.select(C.table_catalog)
Expand Down
10 changes: 9 additions & 1 deletion ibis/backends/oracle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,16 @@
return self

@property
def current_database(self) -> str:
def current_catalog(self) -> str:
with self._safe_raw_sql(sg.select(STAR).from_("global_name")) as cur:
[(catalog,)] = cur.fetchall()
return catalog

Check warning on line 198 in ibis/backends/oracle/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/__init__.py#L197-L198

Added lines #L197 - L198 were not covered by tests

@property
def current_database(self) -> str:
# databases correspond to users, other than that there's
# no notion of a database inside a catalog for oracle
cpcloud marked this conversation as resolved.
Show resolved Hide resolved
with self._safe_raw_sql(sg.select("user").from_("dual")) as cur:
[(database,)] = cur.fetchall()
return database

Expand Down
6 changes: 1 addition & 5 deletions ibis/backends/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_version(backend):
"clickhouse",
"sqlite",
"dask",
"datafusion",
"exasol",
"pandas",
"druid",
Expand All @@ -37,11 +38,6 @@ def test_version(backend):
reason="backend does not support catalogs",
raises=AttributeError,
)
@pytest.mark.notimpl(
["datafusion"],
raises=NotImplementedError,
reason="current_catalog isn't implemented",
)
@pytest.mark.xfail_version(pyspark=["pyspark<3.4"])
def test_catalog_consistency(backend, con):
catalogs = con.list_catalogs()
Expand Down
23 changes: 6 additions & 17 deletions ibis/backends/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,24 +1753,13 @@ def test_cross_database_join(con_create_database, monkeypatch):
["impala", "pyspark", "trino"], reason="Default constraints are not supported"
)
def test_insert_into_table_missing_columns(con, temp_table):
try:
db = getattr(con, "current_database", None)
except NotImplementedError:
db = None

# UGH
if con.name == "oracle":
db = None

try:
catalog = getattr(con, "current_catalog", None)
except NotImplementedError:
catalog = None
db = getattr(con, "current_database", None)

raw_ident = ".".join(
sg.to_identifier(i, quoted=True).sql("duckdb")
for i in filter(None, (catalog, db, temp_table))
)
raw_ident = sg.table(
temp_table,
db=db if db is None else sg.to_identifier(db, quoted=True),
quoted=True,
).sql("duckdb")
cpcloud marked this conversation as resolved.
Show resolved Hide resolved

ct_sql = f'CREATE TABLE {raw_ident} ("a" INT DEFAULT 1, "b" INT)'
sg_expr = sg.parse_one(ct_sql, read="duckdb")
Expand Down