Skip to content

Commit

Permalink
chore: fix list foreign table database kwarg passing
Browse files Browse the repository at this point in the history
  • Loading branch information
ncclementi committed Aug 30, 2024
1 parent 2cd8d31 commit 4c4fc40
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 7 additions & 2 deletions ibis/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,22 @@ def list_temp_views(
self._raise_if_not_implemented("_list_temp_views")
return self._backend._list_temp_views(like=like, database=database)

def list_foreign_tables(self, like: str | None = None) -> list[str]:
def list_foreign_tables(
self, like: str | None = None, database: tuple[str, str] | str | None = None
) -> list[str]:
"""Return the list of foreign table names via the backend's implementation.
Parameters
----------
like
A pattern to use for listing tables.
database
Database to list foreign tables from. Default behavior is to show tables in
the current database.
"""

self._raise_if_not_implemented("_list_foreign_tables")
return self._backend._list_foreign_tables(like=like)
return self._backend._list_foreign_tables(like=like, database=database)


class _FileIOHandler:
Expand Down
16 changes: 13 additions & 3 deletions ibis/backends/postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,20 @@ def _list_temp_views(
def _list_foreign_tables(
self,
like: str | None = None,
):
database: tuple[str, str] | str | None = None,
) -> list[str]:
table_loc = self._warn_and_create_table_loc(database)

catalog = table_loc.catalog or self.current_catalog
database = table_loc.db or self.current_database

col = "foreign_table_name"
where_predicates = [
C.foreign_table_catalog.eq(sge.convert(catalog)),
C.foreign_table_schema.like(sge.convert(database)),
]
sql = self._list_query_constructor(
col, where_predicates=[], tov="foreign_tables"
col, where_predicates=where_predicates, tov="foreign_tables"
)

with self._safe_raw_sql(sql) as cur:
Expand Down Expand Up @@ -469,7 +479,7 @@ def list_tables(
| set(self._list_temp_tables(like=like, database=database))
| set(self._list_views(like=like, database=database))
| set(self._list_temp_views(like=like, database=database))
| set(self._list_foreign_tables(like=like))
| set(self._list_foreign_tables(like=like, database=database))
)

return tables_and_views
Expand Down

0 comments on commit 4c4fc40

Please sign in to comment.