Skip to content

Commit f98a608

Browse files
dungdm93hashhar
authored andcommitted
implement get_catalog_names
Signed-off-by: Đặng Minh Dũng <[email protected]>
1 parent 47bbdd8 commit f98a608

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tests/integration/test_sqlalchemy_integration.py

+9
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,15 @@ def test_json_column(trino_connection, json_object):
410410
metadata.drop_all(engine)
411411

412412

413+
@pytest.mark.parametrize('trino_connection', ['system'], indirect=True)
414+
def test_get_catalog_names(trino_connection):
415+
engine, conn = trino_connection
416+
417+
schemas = engine.dialect.get_catalog_names(conn)
418+
assert len(schemas) == 5
419+
assert set(schemas) == {"jmx", "memory", "system", "tpcds", "tpch"}
420+
421+
413422
@pytest.mark.parametrize('trino_connection', ['memory'], indirect=True)
414423
def test_get_table_comment(trino_connection):
415424
engine, conn = trino_connection

trino/sqlalchemy/dialect.py

+10
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ def get_foreign_keys(
192192
"""Trino has no support for foreign keys. Returns an empty list."""
193193
return []
194194

195+
def get_catalog_names(self, connection: Connection, **kw) -> List[str]:
196+
query = dedent(
197+
"""
198+
SELECT "table_cat"
199+
FROM "system"."jdbc"."catalogs"
200+
"""
201+
).strip()
202+
res = connection.execute(sql.text(query))
203+
return [row.table_cat for row in res]
204+
195205
def get_schema_names(self, connection: Connection, **kw) -> List[str]:
196206
query = dedent(
197207
"""

0 commit comments

Comments
 (0)