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/03/21 21:57:54 UTC
[superset] branch list_catalogs created (now 0c40e07927)
This is an automated email from the ASF dual-hosted git repository.
beto pushed a change to branch list_catalogs
in repository https://gitbox.apache.org/repos/asf/superset.git
at 0c40e07927 feat: get_catalog_names
This branch includes the following new commits:
new 0c40e07927 feat: get_catalog_names
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[superset] 01/01: feat: get_catalog_names
Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch list_catalogs
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 0c40e0792762968ee8008aa03b94e856b9b2c949
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue Mar 21 14:57:42 2023 -0700
feat: get_catalog_names
---
superset/db_engine_specs/base.py | 22 ++++++++++++++++++++++
superset/db_engine_specs/postgres.py | 20 ++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/superset/db_engine_specs/base.py b/superset/db_engine_specs/base.py
index b8b1662057..833e5f5b60 100644
--- a/superset/db_engine_specs/base.py
+++ b/superset/db_engine_specs/base.py
@@ -374,6 +374,14 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
# a custom `adjust_engine_params` method.
supports_dynamic_schema = False
+ # Does the DB support catalogs? A catalog here is a group of schemas, and has different
+ # names depending on the DB: BigQuery calles it a "project", Postgres calls it a
+ # "database", Trino calls it a "catalog", etc.
+ supports_catalog = False
+
+ # Can the catalog be changed on a per-query basis?
+ supports_dynamic_catalog = False
+
@classmethod
def supports_url(cls, url: URL) -> bool:
"""
@@ -1091,6 +1099,20 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
TODO: Improve docstring and refactor implementation in Hive
"""
+ @classmethod
+ def get_catalog_names(
+ cls,
+ database: Database,
+ inspect: Inspector,
+ ) -> List[str]:
+ """
+ Get all catalogs from database.
+
+ This needs to be implemented per database, since SQLAlchemy doesn't offer an
+ abstraction.
+ """
+ return []
+
@classmethod
def get_schema_names(cls, inspector: Inspector) -> List[str]:
"""
diff --git a/superset/db_engine_specs/postgres.py b/superset/db_engine_specs/postgres.py
index fac0b1b1d0..69e9720b68 100644
--- a/superset/db_engine_specs/postgres.py
+++ b/superset/db_engine_specs/postgres.py
@@ -291,6 +291,26 @@ class PostgresEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin):
) -> List[Dict[str, str]]:
return [{k: str(v) for k, v in row.items()} for row in raw_cost]
+ @classmethod
+ def get_catalog_names(
+ cls,
+ database: Database,
+ inspect: Inspector,
+ ) -> List[str]:
+ """
+ Return all catalogs.
+
+ In Postgres, a catalog is called a "database".
+ """
+ return sorted(
+ inspector.bind.execute(
+ """
+SELECT datname FROM pg_database
+WHERE datistemplate = false;
+ """
+ ).fetchall()
+ )
+
@classmethod
def get_table_names(
cls, database: "Database", inspector: PGInspector, schema: Optional[str]