betodealmeida commented on issue #22862:
URL: https://github.com/apache/superset/issues/22862#issuecomment-1405443490
I think a good approach for this would be modifying
`BaseEngineSpec.get_engine` to allow passing a catalog. The method would then
call a DB engine specific method to mutate the SQLAlchemy URI so it uses the
requested catalog. Something like (pseudocode):
```python
BaseEngineSpec:
@classmethod
def get_engine(
cls,
database: Database,
catalog: Optional[str] = None,
schema: Optional[str] = None,
source: Optional[QuerySource] = None,
) -> ContextManager[Engine]:
return database.get_sqla_engine_with_context(
catalog=catalog,
schema=schema,
source=source
)
@classmethod
def apply_catalog_to_sqlalchemy_uri(cls, database: Database, catalog:
str) -> URL:
return database.sqlalchemy_uri
@classmethod
def get_catalog_names(
cls,
database: Database,
inspect: Inspector,
) -> Set[str]:
return set()
```
Individual DB engine specs like Trino/Hive/Snowflake/BigQuery would
implement custom `apply_catalog_to_sqlalchemy_uri` methods to build the
SQLAlchemy URI for a given catalog. They would also implement custom
`get_catalog_names` to list all available catalogs, since there's no standard
SQLAlchemy way of doing that, as far as I know.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]