From 71b1c266648fec330f3df95e8d356d40cd36afd9 Mon Sep 17 00:00:00 2001 From: ncclementi Date: Tue, 13 Aug 2024 17:32:30 -0400 Subject: [PATCH] chore: testing deprecation cycle --- ibis/backends/__init__.py | 29 ++++++++++++++++------------- ibis/backends/duckdb/__init__.py | 26 -------------------------- ibis/backends/tests/test_api.py | 12 ------------ 3 files changed, 16 insertions(+), 51 deletions(-) diff --git a/ibis/backends/__init__.py b/ibis/backends/__init__.py index 08657da4412c4..0e2aef9ac91c7 100644 --- a/ibis/backends/__init__.py +++ b/ibis/backends/__init__.py @@ -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 @@ -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) + + 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) class _FileIOHandler: @@ -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 @@ -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( @@ -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 diff --git a/ibis/backends/duckdb/__init__.py b/ibis/backends/duckdb/__init__.py index fa143c3aa1cb0..747dba0d25a8e 100644 --- a/ibis/backends/duckdb/__init__.py +++ b/ibis/backends/duckdb/__init__.py @@ -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: diff --git a/ibis/backends/tests/test_api.py b/ibis/backends/tests/test_api.py index e1413478be0fa..4b71bdb4ffee8 100644 --- a/ibis/backends/tests/test_api.py +++ b/ibis/backends/tests/test_api.py @@ -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()