diff --git a/ibis/backends/trino/__init__.py b/ibis/backends/trino/__init__.py index 6a3393db0da7..9856e65fb5ec 100644 --- a/ibis/backends/trino/__init__.py +++ b/ibis/backends/trino/__init__.py @@ -45,13 +45,11 @@ def current_database(self) -> str: return self._scalar_query(sa.select(sa.literal_column("current_catalog"))) def list_databases(self, like: str | None = None) -> list[str]: - s = sa.table( - "schemata", - sa.column("catalog_name", sa.VARCHAR()), - schema="information_schema", - ) + query = "SHOW CATALOGS" + with self.begin() as con: + catalogs = list(con.exec_driver_sql(query).scalars()) + return self._filter_with_like(catalogs, like=like) - query = sa.select(sa.distinct(s.c.catalog_name)).order_by(s.c.catalog_name) with self.begin() as con: results = list(con.execute(query).scalars()) return self._filter_with_like(results, like=like) diff --git a/ibis/backends/trino/tests/test_client.py b/ibis/backends/trino/tests/test_client.py index 3b628471e258..362ab794ea5f 100644 --- a/ibis/backends/trino/tests/test_client.py +++ b/ibis/backends/trino/tests/test_client.py @@ -46,3 +46,13 @@ def test_hive_table_overwrite(tmp_name): t = con.create_table(tmp_name, schema=schema, overwrite=True) assert tmp_name in con.list_tables() assert t.schema() == schema + + +def test_list_catalogs(con): + assert {"hive", "postgresql", "memory", "system", "tpch", "tpcds"}.issubset( + con.list_databases() + ) + + +def test_list_schemas(con): + assert {"information_schema", "sf1"}.issubset(con.list_schemas(database="tpch"))