Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snowflake): get_catalog_names #23602

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions superset/db_engine_specs/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
engine_name = "PostgreSQL"

supports_dynamic_schema = True
supports_catalog = True

_time_grain_expressions = {
None: "{col}",
Expand Down
20 changes: 20 additions & 0 deletions superset/db_engine_specs/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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

Expand Down Expand Up @@ -84,6 +85,7 @@ class SnowflakeEngineSpec(PostgresBaseEngineSpec):
sqlalchemy_uri_placeholder = "snowflake://"

supports_dynamic_schema = True
supports_catalog = True

_time_grain_expressions = {
None: "{col}",
Expand Down Expand Up @@ -167,6 +169,24 @@ def get_schema_from_engine_params(

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')"
Expand Down