1from omegaml.backends.basecommon import BackendBaseCommon
2
3
[docs]
4class BaseDataBackend(BackendBaseCommon):
5 """
6 OmegaML BaseDataBackend to be subclassed by other arbitrary backends
7
8 This provides the abstract interface for any data backend to be implemented
9 """
10
11 def __init__(self, model_store=None, data_store=None, tracking=None, **kwargs):
12 assert model_store, "Need a model store"
13 assert data_store, "Need a data store"
14 self.model_store = model_store
15 self.data_store = data_store
16 self.tracking = tracking
17
18 @classmethod
19 def supports(self, obj, name, **kwargs):
20 """
21 test if this backend supports this obj
22 """
23 return False
24
25 def put(self, obj, name, attributes=None, **kwargs):
26 """
27 put an obj
28
29 :param obj: the object to store (object)
30 :param name: the name of the object (str)
31 :param attributes: the attributes dict (dict, optional)
32 :param kwargs: other kwargs to be passed to the Metadata object
33 :return: the Metadata object
34 """
35 raise NotImplementedError
36
37 def get(self, name, version=-1, force_python=False, lazy=False, **kwargs):
38 """
39 get an obj
40
41 :param name: the name of the object (str)
42 :return: the object as it was originally stored
43 """
44 raise NotImplementedError
45
46 def getl(self, *args, **kwargs):
47 """
48 get an lazy implementation to access the obj
49
50 A lazy implementation is a proxy to the object that can be
51 evaluated using the :code:`.value` property. The proxy should
52 ensure that any operations applied on the object are delayed until
53 the .value property is accessed. Typically this is to ensure that
54 the actual computation is executed on the cluster, not on the local
55 machine.
56
57 :param name: the name of the object (str)
58 :return: the proxy to the object as it was originally stored
59 """
60 return self.get(*args, lazy=True, **kwargs)
61
62 def drop(self, name, force=False, version=-1, **kwargs):
63 return self.data_store._drop(name, force=force, version=version, **kwargs)