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 19:17:39 UTC

[superset] branch master updated: feat(snowflake): `get_catalog_names` (#23602)

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 8d14420d14 feat(snowflake): `get_catalog_names` (#23602)
8d14420d14 is described below

commit 8d14420d14e572d9101d772e06c5d980f55502b2
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Thu Apr 6 12:17:30 2023 -0700

    feat(snowflake): `get_catalog_names` (#23602)
---
 superset/db_engine_specs/bigquery.py  |  2 ++
 superset/db_engine_specs/postgres.py  |  1 +
 superset/db_engine_specs/snowflake.py | 20 ++++++++++++++++++++
 3 files changed, 23 insertions(+)

diff --git a/superset/db_engine_specs/bigquery.py b/superset/db_engine_specs/bigquery.py
index 4b36b24eab..f344fcac20 100644
--- a/superset/db_engine_specs/bigquery.py
+++ b/superset/db_engine_specs/bigquery.py
@@ -122,6 +122,8 @@ class BigQueryEngineSpec(BaseEngineSpec):  # pylint: disable=too-many-public-met
 
     allows_hidden_cc_in_orderby = True
 
+    supports_catalog = True
+
     """
     https://www.python.org/dev/peps/pep-0249/#arraysize
     raw_connections bypass the sqlalchemy-bigquery query execution context and deal with
diff --git a/superset/db_engine_specs/postgres.py b/superset/db_engine_specs/postgres.py
index 352c9f466b..99a927541e 100644
--- a/superset/db_engine_specs/postgres.py
+++ b/superset/db_engine_specs/postgres.py
@@ -96,6 +96,7 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
     engine_name = "PostgreSQL"
 
     supports_dynamic_schema = True
+    supports_catalog = True
 
     _time_grain_expressions = {
         None: "{col}",
diff --git a/superset/db_engine_specs/snowflake.py b/superset/db_engine_specs/snowflake.py
index 033b637e48..8b4c51ee8c 100644
--- a/superset/db_engine_specs/snowflake.py
+++ b/superset/db_engine_specs/snowflake.py
@@ -29,6 +29,7 @@ from flask import current_app
 from flask_babel import gettext as __
 from marshmallow import fields, Schema
 from sqlalchemy import types
+from sqlalchemy.engine.reflection import Inspector
 from sqlalchemy.engine.url import URL
 from typing_extensions import TypedDict
 
@@ -84,6 +85,7 @@ class SnowflakeEngineSpec(PostgresBaseEngineSpec):
     sqlalchemy_uri_placeholder = "snowflake://"
 
     supports_dynamic_schema = True
+    supports_catalog = True
 
     _time_grain_expressions = {
         None: "{col}",
@@ -167,6 +169,24 @@ class SnowflakeEngineSpec(PostgresBaseEngineSpec):
 
         return parse.unquote(database.split("/")[1])
 
+    @classmethod
+    def get_catalog_names(
+        cls,
+        database: "Database",
+        inspector: Inspector,
+    ) -> List[str]:
+        """
+        Return all catalogs.
+
+        In Snowflake, a catalog is called a "database".
+        """
+        return sorted(
+            catalog
+            for (catalog,) in inspector.bind.execute(
+                "SELECT DATABASE_NAME from information_schema.databases"
+            )
+        )
+
     @classmethod
     def epoch_to_dttm(cls) -> str:
         return "DATEADD(S, {col}, '1970-01-01')"