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 00:04:03 UTC

[superset] 01/01: feat(snowflake): add `get_catalog_names`

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

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

commit 65254a4edd4b260bbc2e67a41548bf711f541a62
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Wed Apr 5 17:03:43 2023 -0700

    feat(snowflake): add `get_catalog_names`
---
 superset/db_engine_specs/snowflake.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/superset/db_engine_specs/snowflake.py b/superset/db_engine_specs/snowflake.py
index 033b637e48..d0e9580f42 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
 
@@ -167,6 +168,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')"