You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2023/04/06 16:27:58 UTC

[superset] branch master updated: feat(presto): `get_catalog_names` (#23599)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new e2e0ad5ef5 feat(presto): `get_catalog_names` (#23599)
e2e0ad5ef5 is described below

commit e2e0ad5ef5023ca7f7d666c71a2e0a7473edf8ec
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Thu Apr 6 09:27:49 2023 -0700

    feat(presto): `get_catalog_names` (#23599)
---
 superset/db_engine_specs/postgres.py                |  2 +-
 superset/db_engine_specs/presto.py                  | 11 +++++++++++
 .../db_engine_specs/presto_tests.py                 | 21 +++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/superset/db_engine_specs/postgres.py b/superset/db_engine_specs/postgres.py
index e52e69d7e8..352c9f466b 100644
--- a/superset/db_engine_specs/postgres.py
+++ b/superset/db_engine_specs/postgres.py
@@ -310,7 +310,7 @@ class PostgresEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin):
 SELECT datname FROM pg_database
 WHERE datistemplate = false;
             """
-            ).fetchall()
+            )
         )
 
     @classmethod
diff --git a/superset/db_engine_specs/presto.py b/superset/db_engine_specs/presto.py
index c0b4f2c6dd..a9b4f7aa60 100644
--- a/superset/db_engine_specs/presto.py
+++ b/superset/db_engine_specs/presto.py
@@ -785,6 +785,17 @@ class PrestoEngineSpec(PrestoBaseEngineSpec):
             results = cursor.fetchall()
             return {row[0] for row in results}
 
+    @classmethod
+    def get_catalog_names(
+        cls,
+        database: Database,
+        inspector: Inspector,
+    ) -> List[str]:
+        """
+        Get all catalogs.
+        """
+        return [catalog for (catalog,) in inspector.bind.execute("SHOW CATALOGS")]
+
     @classmethod
     def _create_column_info(
         cls, name: str, data_type: types.TypeEngine
diff --git a/tests/integration_tests/db_engine_specs/presto_tests.py b/tests/integration_tests/db_engine_specs/presto_tests.py
index 78b552ecb8..4fe74c0ca3 100644
--- a/tests/integration_tests/db_engine_specs/presto_tests.py
+++ b/tests/integration_tests/db_engine_specs/presto_tests.py
@@ -19,12 +19,14 @@ from textwrap import dedent
 from unittest import mock, skipUnless
 
 import pandas as pd
+from flask.ctx import AppContext
 from sqlalchemy import types
 from sqlalchemy.sql import select
 
 from superset.db_engine_specs.presto import PrestoEngineSpec
 from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
 from superset.sql_parse import ParsedQuery
+from superset.utils.database import get_example_database
 from tests.integration_tests.db_engine_specs.base_tests import TestDbEngineSpec
 
 
@@ -1032,3 +1034,22 @@ def test_is_readonly():
     assert is_readonly("EXPLAIN SELECT 1")
     assert is_readonly("SELECT 1")
     assert is_readonly("WITH (SELECT 1) bla SELECT * from bla")
+
+
+def test_get_catalog_names(app_context: AppContext) -> None:
+    """
+    Test the ``get_catalog_names`` method.
+    """
+    database = get_example_database()
+
+    if database.backend != "presto":
+        return
+
+    with database.get_inspector_with_context() as inspector:
+        assert PrestoEngineSpec.get_catalog_names(database, inspector) == [
+            "jmx",
+            "memory",
+            "system",
+            "tpcds",
+            "tpch",
+        ]