Skip to content

Commit

Permalink
feat: add MotherDuck DB engine spec (#24934)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Aug 9, 2023
1 parent f6c3f0c commit 9c54280
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 21 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def get_git_sha() -> str:
"dremio": ["sqlalchemy-dremio>=1.1.5, <1.3"],
"drill": ["sqlalchemy-drill==0.1.dev"],
"druid": ["pydruid>=0.6.5,<0.7"],
"duckdb": ["duckdb-engine==0.8.1"],
"dynamodb": ["pydynamodb>=0.4.2"],
"solr": ["sqlalchemy-solr >= 0.2.0"],
"elasticsearch": ["elasticsearch-dbapi>=0.2.9, <0.3.0"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,13 @@ const SqlAlchemyTab = ({
testInProgress?: boolean;
children?: ReactNode;
}) => {
let fallbackDocsUrl;
let fallbackDisplayText;
if (SupersetText) {
fallbackDocsUrl =
SupersetText.DB_MODAL_SQLALCHEMY_FORM?.SQLALCHEMY_DOCS_URL;
fallbackDisplayText =
SupersetText.DB_MODAL_SQLALCHEMY_FORM?.SQLALCHEMY_DISPLAY_TEXT;
} else {
fallbackDocsUrl = 'https://docs.sqlalchemy.org/en/13/core/engines.html';
fallbackDisplayText = 'SQLAlchemy docs';
}
const fallbackDocsUrl =
SupersetText?.DB_MODAL_SQLALCHEMY_FORM?.SQLALCHEMY_DOCS_URL ||
'https://docs.sqlalchemy.org/en/13/core/engines.html';
const fallbackDisplayText =
SupersetText?.DB_MODAL_SQLALCHEMY_FORM?.SQLALCHEMY_DISPLAY_TEXT ||
'SQLAlchemy docs';

return (
<>
<StyledInputContainer>
Expand Down Expand Up @@ -82,9 +78,10 @@ const SqlAlchemyTab = ({
data-test="sqlalchemy-uri-input"
value={db?.sqlalchemy_uri || ''}
autoComplete="off"
placeholder={t(
'dialect+driver://username:password@host:port/database',
)}
placeholder={
db?.sqlalchemy_uri_placeholder ||
t('dialect+driver://username:password@host:port/database')
}
onChange={onInputChange}
/>
</div>
Expand Down
11 changes: 9 additions & 2 deletions superset-frontend/src/features/databases/DatabaseModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export type DBReducerActionType =
configuration_method: CONFIGURATION_METHOD;
engine_information?: {};
driver?: string;
sqlalchemy_uri_placeholder?: string;
};
}
| {
Expand Down Expand Up @@ -946,8 +947,13 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const selectedDbModel = availableDbs?.databases.filter(
(db: DatabaseObject) => db.name === database_name,
)[0];
const { engine, parameters, engine_information, default_driver } =
selectedDbModel;
const {
engine,
parameters,
engine_information,
default_driver,
sqlalchemy_uri_placeholder,
} = selectedDbModel;
const isDynamic = parameters !== undefined;
setDB({
type: ActionType.dbSelected,
Expand All @@ -959,6 +965,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
: CONFIGURATION_METHOD.SQLALCHEMY_URI,
engine_information,
driver: default_driver,
sqlalchemy_uri_placeholder,
},
});

Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/features/databases/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type DatabaseObject = {
name: string; // synonym to database_name
paramProperties?: Record<string, any>;
sqlalchemy_uri?: string;
sqlalchemy_uri_placeholder?: string;
parameters?: {
access_token?: string;
database_name?: string;
Expand Down
4 changes: 4 additions & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,9 @@ def available(self) -> Response:
type: array
items:
type: string
sqlalchemy_uri_placeholder:
description: Placeholder for the SQLAlchemy URI
type: string
default_driver:
description: Default driver for the engine
type: string
Expand Down Expand Up @@ -1330,6 +1333,7 @@ def available(self) -> Response:
"name": engine_spec.engine_name,
"engine": engine_spec.engine,
"available_drivers": sorted(drivers),
"sqlalchemy_uri_placeholder": engine_spec.sqlalchemy_uri_placeholder,
"preferred": engine_spec.engine_name in preferred_databases,
"engine_information": engine_spec.get_public_information(),
}
Expand Down
11 changes: 6 additions & 5 deletions superset/db_engine_specs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
engine_aliases: set[str] = set()
drivers: dict[str, str] = {}
default_driver: str | None = None

# placeholder with the SQLAlchemy URI template
sqlalchemy_uri_placeholder = (
"engine+driver://user:password@host:port/dbname[?key=value&key=value...]"
)

disable_ssh_tunneling = False

_date_trunc_functions: dict[str, str] = {}
Expand Down Expand Up @@ -1958,11 +1964,6 @@ class BasicParametersMixin:
# recommended driver name for the DB engine spec
default_driver = ""

# placeholder with the SQLAlchemy URI template
sqlalchemy_uri_placeholder = (
"engine+driver://user:password@host:port/dbname[?key=value&key=value...]"
)

# query parameter to enable encryption in the database connection
# for Postgres this would be `{"sslmode": "verify-ca"}`, eg.
encryption_parameters: dict[str, str] = {}
Expand Down
7 changes: 7 additions & 0 deletions superset/db_engine_specs/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,10 @@ def get_table_names(
cls, database: Database, inspector: Inspector, schema: str | None
) -> set[str]:
return set(inspector.get_table_names(schema))


class MotherDuckEngineSpec(DuckDBEngineSpec):
engine = "duckdb"
engine_name = "MotherDuck"

sqlalchemy_uri_placeholder = "duckdb:///md:{SERVICE_TOKEN}@{database_name}"
3 changes: 3 additions & 0 deletions tests/integration_tests/databases/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3217,6 +3217,7 @@ def test_available(self, app, get_available_engine_specs):
"engine": "hana",
"name": "SAP HANA",
"preferred": False,
"sqlalchemy_uri_placeholder": "engine+driver://user:password@host:port/dbname[?key=value&key=value...]",
"engine_information": {
"supports_file_upload": True,
"disable_ssh_tunneling": False,
Expand Down Expand Up @@ -3248,6 +3249,7 @@ def test_available_no_default(self, app, get_available_engine_specs):
"engine": "mysql",
"name": "MySQL",
"preferred": True,
"sqlalchemy_uri_placeholder": "mysql://user:password@host:port/dbname[?key=value&key=value...]",
"engine_information": {
"supports_file_upload": True,
"disable_ssh_tunneling": False,
Expand All @@ -3258,6 +3260,7 @@ def test_available_no_default(self, app, get_available_engine_specs):
"engine": "hana",
"name": "SAP HANA",
"preferred": False,
"sqlalchemy_uri_placeholder": "engine+driver://user:password@host:port/dbname[?key=value&key=value...]",
"engine_information": {
"supports_file_upload": True,
"disable_ssh_tunneling": False,
Expand Down

0 comments on commit 9c54280

Please sign in to comment.