Skip to content

Commit

Permalink
fix(trino): ensure that list_databases look at all catalogs not just …
Browse files Browse the repository at this point in the history
…the current one
  • Loading branch information
cpcloud committed Aug 31, 2023
1 parent 6973758 commit cfbdbf1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 4 additions & 6 deletions ibis/backends/trino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions ibis/backends/trino/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

0 comments on commit cfbdbf1

Please sign in to comment.