Skip to content

Commit

Permalink
chore: testing deprecation cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
ncclementi committed Aug 13, 2024
1 parent 1726c36 commit 71b1c26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 51 deletions.
29 changes: 16 additions & 13 deletions ibis/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ibis.expr.types as ir
from ibis import util
from ibis.common.caching import RefCountedCache
from ibis.util import deprecated

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Mapping, MutableMapping
Expand Down Expand Up @@ -87,15 +88,23 @@ def _ipython_key_completions_(self) -> list[str]:
return self._backend.list_tables()


class DdlAccessor:
class DDLAccessor:
"""ddl accessor list views."""

def __init__(self, backend: BaseBackend):
self._backend = backend

def list_views(self) -> list[str]:
"""List the names of views in the database."""
return self._backend.list_views()
def list_tables(
self, like: str | None = None, database: tuple[str, str] | str | None = None
) -> list[str]:
"""Return the list of table names via the backend's implementation."""
return self._backend.list_tables(like=like, database=database)

Check warning on line 101 in ibis/backends/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/__init__.py#L101

Added line #L101 was not covered by tests

def list_views(
self, like: str | None = None, database: tuple[str, str] | str | None = None
) -> list[str]:
"""Return the list of view names via the backend's implementation."""
return self._backend.list_views(like=like, database=database)

Check warning on line 107 in ibis/backends/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/__init__.py#L107

Added line #L107 was not covered by tests


class _FileIOHandler:
Expand Down Expand Up @@ -906,14 +915,7 @@ def _filter_with_like(values: Iterable[str], like: str | None = None) -> list[st
pattern = re.compile(like)
return sorted(filter(pattern.findall, values))

@abc.abstractmethod
def list_views(
self,
like: str | None = None,
database: str | None = None,
) -> list[str]:
"""List the names of views in the database."""

@deprecated(as_of="10.0", instead="use the con.ddl.list_tables()")
@abc.abstractmethod
def list_tables(
self, like: str | None = None, database: tuple[str, str] | str | None = None
Expand Down Expand Up @@ -951,6 +953,7 @@ def list_tables(
The list of the table names that match the pattern `like`.
"""
return self.ddl.list_tables(like=like, database=database)

@abc.abstractmethod
def table(
Expand Down Expand Up @@ -1005,7 +1008,7 @@ def tables(self):
@functools.cached_property
def ddl(self):
"""A ddl accessor."""
return DdlAccessor(self)
return DDLAccessor(self)

@property
@abc.abstractmethod
Expand Down
26 changes: 0 additions & 26 deletions ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,32 +1037,6 @@ def list_tables(

return self._filter_with_like(out[col].to_pylist(), like)

def list_views(
self,
like: str | None = None,
database: tuple[str, str] | str | None = None,
schema: str | None = None,
) -> list[str]:
"""List views."""
# return ["test1", "test2"]
table_loc = self._warn_and_create_table_loc(database, schema)

database = self.compiler.f.current_schema()
if table_loc is not None:
database = table_loc.db or database

col = "view_name"
sql = (
sg.select(col)
.from_(sg.table("duckdb_views"))
.distinct()
.where(C.schema_name.eq(database))
.sql(self.name, pretty=True)
)
out = self.con.execute(sql).fetch_arrow_table()

return self._filter_with_like(out[col].to_pylist(), like)

def read_postgres(
self, uri: str, *, table_name: str | None = None, database: str = "public"
) -> ir.Table:
Expand Down
12 changes: 0 additions & 12 deletions ibis/backends/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,3 @@ def test_unbind(alltypes, expr_fn):

assert "Unbound" not in repr(expr)
assert "Unbound" in repr(expr.unbind())


###for now let's just try duckdb
def test_list_views(ddl_con, temp_view):
expr = ddl_con.table("functional_alltypes")
ddl_con.create_view(temp_view, expr)

views = ddl_con.list_views()
assert isinstance(views, list)
assert temp_view in views

assert temp_view not in ddl_con.list_tables()

0 comments on commit 71b1c26

Please sign in to comment.