Skip to content

Commit

Permalink
implement get_catalog_names
Browse files Browse the repository at this point in the history
Signed-off-by: Đặng Minh Dũng <[email protected]>
  • Loading branch information
dungdm93 authored and hashhar committed Aug 31, 2023
1 parent 47bbdd8 commit f98a608
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/integration/test_sqlalchemy_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,15 @@ def test_json_column(trino_connection, json_object):
metadata.drop_all(engine)


@pytest.mark.parametrize('trino_connection', ['system'], indirect=True)
def test_get_catalog_names(trino_connection):
engine, conn = trino_connection

schemas = engine.dialect.get_catalog_names(conn)
assert len(schemas) == 5
assert set(schemas) == {"jmx", "memory", "system", "tpcds", "tpch"}


@pytest.mark.parametrize('trino_connection', ['memory'], indirect=True)
def test_get_table_comment(trino_connection):
engine, conn = trino_connection
Expand Down
10 changes: 10 additions & 0 deletions trino/sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ def get_foreign_keys(
"""Trino has no support for foreign keys. Returns an empty list."""
return []

def get_catalog_names(self, connection: Connection, **kw) -> List[str]:
query = dedent(
"""
SELECT "table_cat"
FROM "system"."jdbc"."catalogs"
"""
).strip()
res = connection.execute(sql.text(query))
return [row.table_cat for row in res]

def get_schema_names(self, connection: Connection, **kw) -> List[str]:
query = dedent(
"""
Expand Down

0 comments on commit f98a608

Please sign in to comment.