smarzola / sqlalchemy-mongobi

MongoDB connector for BI SQLAlchemy Dialect
MIT License
14 stars 1 forks source link

Add db engine spec for mongo bi connector #2

Open jbouzekri opened 3 years ago

jbouzekri commented 3 years ago

Description

I made a poc repository using your package to query a mongodb database using superset. I talked about it on the superset repository and somebody mentioned that you are missing a db engine spec implementation for your connector : https://github.com/apache/superset/issues/13930#issuecomment-891556950

I am pretty sure that you could use almost the same as mysql with one or two changes.

Deninc commented 2 years ago

@jbouzekri do you have any idea to overcome this? Seems like superset is missing some features because of this.

jbouzekri commented 2 years ago

@Deninc I looked a little into it at the time I made my PoC but not too deep. I think you will have either to fork this repository or create your own python package to reference the custom engine spec that match the mongobi engine.

If you look into the load_engine_specs https://github.com/apache/superset/blob/0d331f5bd81f25bc92a20da6ed8d99f0c393efb2/superset/db_engine_specs/__init__.py#L56, the way to add a custom spec is through the superset.db_engine_specs entrypoint.

So in your setup.py of your package, if you add something like this :

entry_points={
    'superset.db_engine_specs': [
        'mongobi = mongobi:MongobiSpec',
    ],
}

This will reference a MongobiSpec class in a mongobi module. The load_engine_specs from superset should be able to load it. Then you make this class extend from superset.db_engine_specs.base import BaseEngineSpec or better the one from a sql engine which is the nearest in behavior as mongobi connector.

Then your engine spec should have mongobi as a name if I look into the get_engine_spec from engine name function https://github.com/apache/superset/blob/f64d654de3d3ce3246badedadd4065343d98d4ee/superset/databases/schemas.py#L298

So a class like that :

from superset.db_engine_specs.base import BaseEngineSpec

class MongobiSpec(BaseEngineSpec):
    engine = "mongobi"

At the time I made my PoC to try this and debug I cloned the superset repository and directly coded into it. It was easier to put breakpoints and other stops in the code.