From 84d38a1e9cd67eb480ed9faa4fc506f98247dea3 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Thu, 10 Aug 2023 05:01:22 -0400 Subject: [PATCH] fix(trino): override incorrect base sqlalchemy `list_schemas` implementation --- ibis/backends/trino/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ibis/backends/trino/__init__.py b/ibis/backends/trino/__init__.py index 9856e65fb5ec..1c6132edf728 100644 --- a/ibis/backends/trino/__init__.py +++ b/ibis/backends/trino/__init__.py @@ -50,9 +50,17 @@ def list_databases(self, like: str | None = None) -> list[str]: catalogs = list(con.exec_driver_sql(query).scalars()) return self._filter_with_like(catalogs, like=like) + def list_schemas( + self, like: str | None = None, database: str | None = None + ) -> list[str]: + query = "SHOW SCHEMAS" + + if database is not None: + query += f" IN {self._quote(database)}" + with self.begin() as con: - results = list(con.execute(query).scalars()) - return self._filter_with_like(results, like=like) + schemata = list(con.exec_driver_sql(query).scalars()) + return self._filter_with_like(schemata, like) @property def current_schema(self) -> str: @@ -108,7 +116,7 @@ def column_reflect(inspector, table, column_info): @contextlib.contextmanager def _prepare_metadata(self, query: str) -> Iterator[dict[str, str]]: - name = util.gen_name("ibis_trino_metadata") + name = util.gen_name("trino_metadata") with self.begin() as con: con.exec_driver_sql(f"PREPARE {name} FROM {query}") try: