Skip to content

Commit

Permalink
Add databackend option in superduper magic method
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik4949 committed Nov 28, 2023
1 parent 5b6e341 commit e60f3e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions superduperdb/base/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ def build_compute(cfg):
return LocalComputeBackend()


def build_datalayer(cfg=None, **kwargs) -> Datalayer:
def build_datalayer(cfg=None, databackend=None, **kwargs) -> Datalayer:
"""
Build a Datalayer object as per ``db = superduper(db)`` from configuration.
:param cfg: Configuration to use. If None, use ``superduperdb.CFG``.
:param databackend: Databacked to use.
If None, use ``superduperdb.CFG.data_backend``.
"""

# Configuration
Expand All @@ -87,7 +89,8 @@ def build_datalayer(cfg=None, **kwargs) -> Datalayer:
# Connect to data backend.
# ------------------------------
try:
databackend = build(cfg.data_backend, data_backends)
if not databackend:
databackend = build(cfg.data_backend, data_backends)
logging.info("Data Client is ready.", databackend.conn)
except Exception as e:
# Exit quickly if a connection fails.
Expand Down
11 changes: 9 additions & 2 deletions superduperdb/base/superduper.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,16 @@ def create(cls, item: t.Any, **kwargs) -> t.Any:
if not isinstance(item, (Database, MockDatabase)):
raise TypeError(f'Expected Database but got {type(item)}')

logging.warn('Note: This is only recommended in development mode')
logging.warn(
'Note: This is only recommended in development mode, since config\
still holds `data_backend` with the default value, services \
like vector search and cdc cannot be reached due to configuration\
mismatch. Services will be configured with a `data_backend` uri using \
config file hence this client config and\
services config will be different.'
)
databackend = MongoDataBackend(conn=item.client, name=item.name)
return build_datalayer(cfg=CFG, data_backend=databackend, **kwargs)
return build_datalayer(cfg=CFG, databackend=databackend, **kwargs)


class SklearnTyper(_DuckTyper):
Expand Down

0 comments on commit e60f3e6

Please sign in to comment.