code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def apply( self, object: t.Union[Component, t.Sequence[t.Any], t.Any], force: bool | None = None, wait: bool = False, jobs: bool = True, ): """ Add functionality in the form of components. Components are stored in the configured artifact store ...
Add functionality in the form of components. Components are stored in the configured artifact store and linked to the primary database through metadata. :param object: Object to be stored. :param force: Force apply. :param wait: Wait for apply events. :param jo...
apply
python
superduper-io/superduper
superduper/base/datalayer.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datalayer.py
Apache-2.0
def _filter_deletions_by_cascade(self, events: t.List[Delete]): """ Filter deletions by cascade. :param events: List of events to filter. """ all_huuids = set(e.huuid for e in events) lookup = {e.huuid: e for e in events} graph = nx.DiGraph() for e in e...
Filter deletions by cascade. :param events: List of events to filter.
_filter_deletions_by_cascade
python
superduper-io/superduper
superduper/base/datalayer.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datalayer.py
Apache-2.0
def remove( self, component: str, identifier: str, recursive: bool = False, force: bool = False, ): """ Remove a component (version optional). :param component: Cmponent to remove ('Model', 'Listener', etc.) :param identifier: Identifier of th...
Remove a component (version optional). :param component: Cmponent to remove ('Model', 'Listener', etc.) :param identifier: Identifier of the component (refer to `container.base.Component`). :param recursive: Toggle to remove all descendants of the component....
remove
python
superduper-io/superduper
superduper/base/datalayer.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datalayer.py
Apache-2.0
def load_all(self, component: str, **kwargs) -> t.List[Component]: """Load all instances of component. :param component: Component class :param kwargs: Addition key-value pairs to `self.load` """ identifiers = self.metadata.show_components(component=component) out: t.Lis...
Load all instances of component. :param component: Component class :param kwargs: Addition key-value pairs to `self.load`
load_all
python
superduper-io/superduper
superduper/base/datalayer.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datalayer.py
Apache-2.0
def load( self, component: str, identifier: t.Optional[str] = None, version: t.Optional[int] = None, uuid: t.Optional[str] = None, huuid: t.Optional[str] = None, overrides: t.Dict | None = None, component_cache: bool = True, ) -> Component: """...
Load a component using uniquely identifying information. If `uuid` is provided, `component` and `identifier` are ignored. If `uuid` is not provided, `component` and `identifier` must be provided. :param component: Type ID of the component to load ('datatype', ...
load
python
superduper-io/superduper
superduper/base/datalayer.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datalayer.py
Apache-2.0
def select_nearest( self, like: t.Union[t.Dict, Document], vector_index: str, ids: t.Optional[t.Sequence[str]] = None, outputs: t.Optional[Document] = None, n: int = 100, ) -> t.Tuple[t.List[str], t.List[float]]: """ Performs a vector search query on t...
Performs a vector search query on the given vector index. :param like: Vector search document to search. :param vector_index: Vector index to search. :param ids: (Optional) IDs to search within. :param outputs: (Optional) Seed outputs dictionary. :param n: Get top k res...
select_nearest
python
superduper-io/superduper
superduper/base/datalayer.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datalayer.py
Apache-2.0
def cfg(self, cfg: Config): """Set the configuration object for the datalayer.""" assert isreallyinstance(cfg, Config) self._cfg = cfg
Set the configuration object for the datalayer.
cfg
python
superduper-io/superduper
superduper/base/datalayer.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datalayer.py
Apache-2.0
def encode_data(self, item, context): """Encode the given item into a bytes-like object or reference. :param item: The object/instance to encode. :param context: A context object containing caches. """
Encode the given item into a bytes-like object or reference. :param item: The object/instance to encode. :param context: A context object containing caches.
encode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def decode_data(self, item, builds, db): """Decode the item from bytes. :param item: The item to decode. :param builds: The build-cache dictionary. :param db: The datalayer. """
Decode the item from bytes. :param item: The item to decode. :param builds: The build-cache dictionary. :param db: The datalayer.
decode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def decode_data(self, item, builds, db): """Decode the item from `bytes`. :param item: The item to decode. :param builds: The build-cache dictionary. :param db: The Datalayer. """ if isinstance(item, str) and item.startswith('?'): key = item[1:] i...
Decode the item from `bytes`. :param item: The item to decode. :param builds: The build-cache dictionary. :param db: The Datalayer.
decode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def decode_data(self, item, builds, db): """Decode the item from `bytes`. :param item: The item to decode. :param builds: The build cache. :param db: The Datalayer. """
Decode the item from `bytes`. :param item: The item to decode. :param builds: The build cache. :param db: The Datalayer.
decode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def encode_data(self, item, context): """Encode the item as a list of floats. :param item: The object/instance to encode. :param context: A context object containing caches. """ if isinstance(item, numpy.ndarray): item = item.tolist() return item
Encode the item as a list of floats. :param item: The object/instance to encode. :param context: A context object containing caches.
encode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def encode_data(self, item, context): """Encode the item as a JSON-compatible form or string. :param item: The object/instance to encode. :param context: A context object containing caches. """ try: json.dumps(item) except Exception: raise TypeErr...
Encode the item as a JSON-compatible form or string. :param item: The object/instance to encode. :param context: A context object containing caches.
encode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def hash_indescript(item): """Hash a range of items. :param item: The item to hash. """ if inspect.isfunction(item): module = item.__module__ try: body = f'{module}\n{inspect.getsource(item)}' return hashlib.sha256(body.encode()).hexdigest() except OSErro...
Hash a range of items. :param item: The item to hash.
hash_indescript
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def decode_data(self, item, builds, db): """Decode the item from `bytes`. :param item: The item to decode. :param builds: The build cache :param db: The datalayer. """ if isinstance(item, Blob): return item assert isinstance(item, str) assert ...
Decode the item from `bytes`. :param item: The item to decode. :param builds: The build cache :param db: The datalayer.
decode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def encode_data(self, item, context): """Encode the item as a file path. :param item: The object/instance to encode. :param context: A context object containing caches. """ if isinstance(item, FileItem): file = item else: assert os.path.exists(ite...
Encode the item as a file path. :param item: The object/instance to encode. :param context: A context object containing caches.
encode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def decode_data(self, item, builds, db): """Decode the item placeholder. :param item: The file path to decode. :param builds: The build cache. :param db: Datalayer. """ file_id = item.split(':')[-1] path = db.artifact_store.get_file(file_id) return FileIt...
Decode the item placeholder. :param item: The file path to decode. :param builds: The build cache. :param db: Datalayer.
decode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def decode_data(self, item, builds, db): """Decode the data. :param item: The data to decode. :param builds: The build cache :param db: The datalayer. """ shape = self.shape if isinstance(shape, int): shape = (self.shape,) return numpy.frombuf...
Decode the data. :param item: The data to decode. :param builds: The build cache :param db: The datalayer.
decode_data
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def get_hash(data): """Get the hash of the given data. :param data: Data to hash. """ if isinstance(data, str): bytes_ = data.encode() elif isinstance(data, bytes): bytes_ = data else: bytes_ = str(id(data)).encode() return hashlib.sha1(bytes_).hexdigest()
Get the hash of the given data. :param data: Data to hash.
get_hash
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def setup(self): """Initialize the file to local disk.""" if self.path: return self.path = self.db.artifact_store.get_file(self.identifier)
Initialize the file to local disk.
setup
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def unpack(self): """Get the bytes out of the blob.""" if self.bytes is None: self.setup() return self.builder(self.bytes)
Get the bytes out of the blob.
unpack
python
superduper-io/superduper
superduper/base/datatype.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/datatype.py
Apache-2.0
def _update(r, s): # TODO - how to deal with unordered sets? """ Update a dictionary with another dictionary, also nested. >>> r = {'a': 1, 'b': {'c': 2, 'd': 3}} >>> s = {'b': {'c': 4}} >>> _update(r, s) {'a': 1, 'b': {'c': 4, 'd': 3}} """ for k in s: if isinstance(s[k], di...
Update a dictionary with another dictionary, also nested. >>> r = {'a': 1, 'b': {'c': 2, 'd': 3}} >>> s = {'b': {'c': 4}} >>> _update(r, s) {'a': 1, 'b': {'c': 4, 'd': 3}}
_update
python
superduper-io/superduper
superduper/base/document.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/document.py
Apache-2.0
def get_bytes(self, file_id: str) -> bytes: """ Load bytes from artifact store. :param file_id: Identifier of artifact in the store """ if file_id in self.blobs: return self.blobs[file_id] elif self.artifact_store: return self.artifact_store.get_b...
Load bytes from artifact store. :param file_id: Identifier of artifact in the store
get_bytes
python
superduper-io/superduper
superduper/base/document.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/document.py
Apache-2.0
def get_file(self, file_id: str) -> str: """ Load file from artifact store and return path. :param file_id: Identifier of artifact in the store """ if file_id in self.files: return self.files[file_id] elif self.artifact_store: return self.artifact...
Load file from artifact store and return path. :param file_id: Identifier of artifact in the store
get_file
python
superduper-io/superduper
superduper/base/document.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/document.py
Apache-2.0
def map(self, fn, condition): """Map a function over the document. :param fn: The function to map. :param condition: The condition to map over. """ def _map(r): if isinstance(r, dict): out = {} for k, v in r.items(): ...
Map a function over the document. :param fn: The function to map. :param condition: The condition to map over.
map
python
superduper-io/superduper
superduper/base/document.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/document.py
Apache-2.0
def diff(self, other: 'Document'): """Get a `Document` with the difference to `other` inside. :param other: Other `Document`. """ out: t.Dict = {} _diff(self, other, out) return Document(out, schema=self.schema)
Get a `Document` with the difference to `other` inside. :param other: Other `Document`.
diff
python
superduper-io/superduper
superduper/base/document.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/document.py
Apache-2.0
def update(self, other: t.Union['Document', dict]): """Update document with values from other. :param other: The other document to update with. """ schema = self.schema or Schema(fields={}) if isinstance(other, Document) and other.schema: assert other.schema is not ...
Update document with values from other. :param other: The other document to update with.
update
python
superduper-io/superduper
superduper/base/document.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/document.py
Apache-2.0
def encode( self, schema: t.Optional['Schema'] = None, context: EncodeContext | None = None, **kwargs, ) -> t.Dict: """Encode the document to a format that can be used in a database. After encoding everything is a vanilla dictionary (JSON + bytes). (Even a mo...
Encode the document to a format that can be used in a database. After encoding everything is a vanilla dictionary (JSON + bytes). (Even a model, or artifact etc..) :param schema: The schema to use. :param context: The encoding context. :param kwargs: Additional encoding argumen...
encode
python
superduper-io/superduper
superduper/base/document.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/document.py
Apache-2.0
def decode( cls, r, schema: t.Optional['Schema'] = None, db: t.Optional['Datalayer'] = None, ): """Converts any dictionary into a Document or a Leaf. :param r: The encoded data. :param schema: The schema to use. :param db: The datalayer to use. ...
Converts any dictionary into a Document or a Leaf. :param r: The encoded data. :param schema: The schema to use. :param db: The datalayer to use.
decode
python
superduper-io/superduper
superduper/base/document.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/document.py
Apache-2.0
def batch_execute( cls, events: t.List['Event'], db: 'Datalayer', batch_size: int | None = None ): """Execute the events in batch. :param events: list of events. :param db: Datalayer instance. :param batch_size: size of the batch. """ for event in events: ...
Execute the events in batch. :param events: list of events. :param db: Datalayer instance. :param batch_size: size of the batch.
batch_execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def execute( self, db: 'Datalayer', ): """Execute the event. :param db: Datalayer instance. """ raise NotImplementedError('Not relevant for this event class')
Execute the event. :param db: Datalayer instance.
execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def execute( self, db: 'Datalayer', ): """Execute the signal. :param db: Datalayer instance. """ if self.msg.lower() == 'done': db.cluster.compute.release_futures(self.context)
Execute the signal. :param db: Datalayer instance.
execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def execute( self, db: 'Datalayer', ): """Execute the change event. :param db: Datalayer instance. """ raise NotImplementedError('Not relevant for this event class')
Execute the change event. :param db: Datalayer instance.
execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def batch_execute( cls, events: t.List['CreateTable'], db: 'Datalayer', batch_size: int | None = None, ): """Execute the create table events in batch. :param events: list of create table events. :param db: Datalayer instance. """ batch_size = ...
Execute the create table events in batch. :param events: list of create table events. :param db: Datalayer instance.
batch_execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def execute(self, db: 'Datalayer'): """Execute the create event. :param db: Datalayer instance. """ return db.metadata.create_table_and_schema( identifier=self.identifier, primary_id=self.primary_id, schema=Schema.build(**self.fields), is_...
Execute the create event. :param db: Datalayer instance.
execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def cluster_by_component(events: t.List['Create']): """Cluster events by component. :param events: list of create events. :return: list of create events clustered by component. """ clustered_events: t.Dict = defaultdict(list) for event in events: if event.com...
Cluster events by component. :param events: list of create events. :return: list of create events clustered by component.
cluster_by_component
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def batch_execute( cls, events: t.List['PutComponent'], db: 'Datalayer', batch_size: int | None = None, ): """Execute the put component events in batch. :param events: list of put component events :param db: Datalayer instance. :param batch_size: size...
Execute the put component events in batch. :param events: list of put component events :param db: Datalayer instance. :param batch_size: size of the batch.
batch_execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def execute(self, db: 'Datalayer'): """Execute the put on cluster event. :param db: Datalayer instance. """ logging.info( f'Putting {self.component}:' f'{self.identifier}:{self.uuid} on {self.service}' ) getattr(db.cluster, self.service).put_compo...
Execute the put on cluster event. :param db: Datalayer instance.
execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def execute(self, db: 'Datalayer'): """Execute the delete event. :param db: Datalayer instance. """ try: object = db.load(component=self.component, identifier=self.identifier) object.cleanup() db.metadata.delete_component(self.component, self.identifi...
Execute the delete event. :param db: Datalayer instance.
execute
python
superduper-io/superduper
superduper/base/event.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/event.py
Apache-2.0
def patcher(record): """Patch the logger to add the relative path of the file. :param record: The log record. """ abs_path = record["file"].path if abs_path.startswith(PROJECT_ROOT): rel_path = os.path.relpath(abs_path, PROJECT_ROOT) else: rel_path = os.path.basename(abs_path) ...
Patch the logger to add the relative path of the file. :param record: The log record.
patcher
python
superduper-io/superduper
superduper/base/logger.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/logger.py
Apache-2.0
def wait(self, db: 'Datalayer', heartbeat: float = 1, timeout: int = 60): """Wait for the job to finish. :param db: Datalayer instance :param heartbeat: time to wait between checks :param timeout: timeout in seconds :raises Exception: if job remains uninitialized or pending for...
Wait for the job to finish. :param db: Datalayer instance :param heartbeat: time to wait between checks :param timeout: timeout in seconds :raises Exception: if job remains uninitialized or pending for more than timeout seconds :raises Exception: if job fails :raises Ex...
wait
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_args_kwargs(self, futures): """Get args and kwargs for job execution. :param futures: dict of futures """ from superduper.backends.base.scheduler import Future dependencies = [] if self.dependencies: dependencies = [futures[k] for k in self.dependenc...
Get args and kwargs for job execution. :param futures: dict of futures
get_args_kwargs
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def fix(db, context: str): """Fix the job. :param db: Datalayer instance :param context: context of the job """ failed_jobs = ( db['Job'] .filter( db['Job']['context'] == context, db['Job']['status'] == STATUS_FAILED ) ...
Fix the job. :param db: Datalayer instance :param context: context of the job
fix
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def set_failed(self, db: 'Datalayer', reason: str, message: str | None = None): """Set the job status to failed. :param db: Datalayer instance :param reason: reason for failure :param message: error message """ logging.info(f'Setting job status {self.job_id} to failed') ...
Set the job status to failed. :param db: Datalayer instance :param reason: reason for failure :param message: error message
set_failed
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def set_status( self, db: 'Datalayer', status: str, reason: str, message: str | None = None, was_broken: bool = False, ): """ Set the status of a job. :param db: Datalayer instance :param status: status to set :param reason: re...
Set the status of a job. :param db: Datalayer instance :param status: status to set :param reason: reason for status change :param message: message for status change :param was_broken: whether the job was broken before
set_status
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_status(self, db: 'Datalayer'): """Get the job status. :param db: Datalayer instance """ j = db['Job'].get(job_id=self.job_id) if j is None: return STATUS_UNINITIALIZED return j['status'], j['details']
Get the job status. :param db: Datalayer instance
get_status
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def run(self, db: 'Datalayer'): """Run the job. :param db: Datalayer instance """ was_broken = False try: status, details = self.get_status(db) if status == STATUS_FAILED: raise exceptions.InternalError( 'Upstream job f...
Run the job. :param db: Datalayer instance
run
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def save_output(self, db: 'Datalayer', result: t.Any): """Save the output of the job. :param db: Datalayer instance :param result: result of the job """ logging.info(f'Saving output for job {self.huuid}') db['Job'].update({'job_id': self.job_id}, 'result', result) ...
Save the output of the job. :param db: Datalayer instance :param result: result of the job
save_output
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def execute( self, db: 'Datalayer', ): """Execute the job event. :param db: Datalayer instance """ entry = db['Job'].get(job_id=self.job_id) if entry is None: db.metadata.create_job(dict(self.dict())) return db.cluster.compute.submit(self)
Execute the job event. :param db: Datalayer instance
execute
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def cache(self): """Context manager to enable and manage component class information caching.""" current_cache = _component_cache.get() if current_cache is None: token = _component_cache.set({}) else: token = None try: yield finally: ...
Context manager to enable and manage component class information caching.
cache
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def check_table_in_metadata(self, table: str): """Check if a table exists in the metadata store. :param table: table name. """ if table in metaclasses: return True return table in self.db.databackend.list_tables()
Check if a table exists in the metadata store. :param table: table name.
check_table_in_metadata
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_primary_id(self, table: str): """Get the primary id of a table. :param table: table name. """ pid = self.primary_ids.get(table) if pid is None: pid = self.get_component(component="Table", identifier=table, version=0)[ "primary_id" ...
Get the primary id of a table. :param table: table name.
get_primary_id
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def create_tables_and_schemas(self, events: t.List['CreateTable']): """Create a table and schema in the metadata store. :param events: list of create table events. """ metadata_tables = [e for e in events if e.is_component] main_tables = [e for e in events if not e.is_component]...
Create a table and schema in the metadata store. :param events: list of create table events.
create_tables_and_schemas
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def create_table_and_schema( self, identifier: str, schema: 'Schema', primary_id: str, is_component: bool, ): """Create a table and schema in the metadata store. :param identifier: table name :param schema: schema of the table :param primary_i...
Create a table and schema in the metadata store. :param identifier: table name :param schema: schema of the table :param primary_id: primary id of the table :param is_component: whether the table is a component
create_table_and_schema
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def drop(self, force: bool = False): """Drop the metadata store. :param force: whether to force drop the metadata store. """ if not force and not click.confirm( 'Are you sure you want to drop the metadata store?' ): logging.warn('Aborting drop of metadata...
Drop the metadata store. :param force: whether to force drop the metadata store.
drop
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_schema(self, table: str): """Get the schema of a table. :param table: table name. """ if table in metaclasses: return metaclasses[table].class_schema r = self._get_component_class_info(table) fields = r['fields'] schema = Schema.build(**fiel...
Get the schema of a table. :param table: table name.
get_schema
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def create(self, cls: t.Type[Base]): """ Create a table in the metadata store. :param cls: class to create """ try: r = self._get_component_class_info(cls.__name__) if r is not None: return except exceptions.NotFound: p...
Create a table in the metadata store. :param cls: class to create
create
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def delete_parent_child_relationships( self, parent_component: str, parent_identifier: str ): """ Delete parent-child mappings. :param parent_component: parent component type :param parent_identifier: parent component identifier """ self.db['ParentChildAssoci...
Delete parent-child mappings. :param parent_component: parent component type :param parent_identifier: parent component identifier
delete_parent_child_relationships
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def create_component(self, info: t.Dict, path: str, raw: bool = True): """ Create a component in the metadata store. :param info: dictionary containing information about the component. :param path: path to the component class. :param raw: whether to insert raw data. """ ...
Create a component in the metadata store. :param info: dictionary containing information about the component. :param path: path to the component class. :param raw: whether to insert raw data.
create_component
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def create_parent_child( self, parent_component: str, parent_identifier: str, parent_uuid: str, child_component: str, child_identifier: str, child_uuid: str, ): """ Create a parent-child relationship between two components. :param pare...
Create a parent-child relationship between two components. :param parent_component: parent component type :param parent_identifier: parent component identifier :param parent_uuid: parent uuid :param child_component: child component type :param child_identifier: child co...
create_parent_child
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def create_artifact_relation(self, component, identifier, uuid, artifact_ids): """ Create a relation between an artifact and a component version. :param component: type of component :param identifier: identifier of component :param uuid: UUID of component version :param ...
Create a relation between an artifact and a component version. :param component: type of component :param identifier: identifier of component :param uuid: UUID of component version :param artifact_ids: artifact
create_artifact_relation
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def delete_artifact_relation( self, component: str, identifier: str, artifact_ids: t.List[str] ): """ Delete a relation between an artifact and a component version. :param component: type of component :param identifier: identifier of component :param artifact_ids: ar...
Delete a relation between an artifact and a component version. :param component: type of component :param identifier: identifier of component :param artifact_ids: artifact ids
delete_artifact_relation
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_artifact_relations_for_component(self, component, identifier): """ Get all relations between an artifact and a component version. :param component: type of component :param identifier: identifier of component """ t = self.db['ArtifactRelations'] relations...
Get all relations between an artifact and a component version. :param component: type of component :param identifier: identifier of component
get_artifact_relations_for_component
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def set_component_failed( self, component: str, uuid: str, failed_child: t.Tuple[str, t.Dict] | None = None, message: str | None = None, reason: str | None = None, context: str | None = None, ): """ Set the status of a component to failed. ...
Set the status of a component to failed. :param component: type of component :param uuid: ``Component.uuid`` :param failed_child: child to fail :param message: error message :param reason: reason for failure :param context: context of the failure
set_component_failed
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def set_component_fixed( self, component: str, uuid: str, fixed_child: str, ): """ Set the status of a component to fixed. :param component: type of component :param uuid: ``Component.uuid`` :param fixed_child: Child to fix """ ...
Set the status of a component to fixed. :param component: type of component :param uuid: ``Component.uuid`` :param fixed_child: Child to fix
set_component_fixed
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def set_component_status( self, component: str, uuid: str, status: str, reason: str, message: str | None = None, ): """ Set the status of a component. :param component: type of component :param uuid: ``Component.uuid`` :param s...
Set the status of a component. :param component: type of component :param uuid: ``Component.uuid`` :param status: Status to set :param reason: reason for status change :param message: message for status change
set_component_status
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def show_jobs(self, component: str, identifier: str, status: str | None = None): """ Show all jobs in the metadata store. :param component: type of component :param identifier: identifier of component :param status: status of job """ filters = [ self....
Show all jobs in the metadata store. :param component: type of component :param identifier: identifier of component :param status: status of job
show_jobs
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def show_components(self, component: str | None = None): """ Show all components in the metadata store. :param component: type of component """ if component is None: out = [] t = self.db['Table'] components = t.filter(t['is_component'] == Tru...
Show all components in the metadata store. :param component: type of component
show_components
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def show_status(self, component: str, identifier: str | None = None): """ Show the status of a component. :param component: type of component :param identifier: identifier of component """ if component is None: raise exceptions.NotFound(component, identifier)...
Show the status of a component. :param component: type of component :param identifier: identifier of component
show_status
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def show_cdc_tables(self): """List the tables used for CDC.""" metadata = self.db['Table'].execute() cdc_classes = [] for r in metadata: if r['path'] is None: continue cls = import_object(r['path']) r = r.unpack() if issubc...
List the tables used for CDC.
show_cdc_tables
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def show_cdcs(self, table): """ Show the ``CDC`` components running on a given table. :param table: ``Table`` to consider. """ cdc_classes = [] metadata = self.db['Table'].execute() for r in metadata: if r['path'] is None: continue ...
Show the ``CDC`` components running on a given table. :param table: ``Table`` to consider.
show_cdcs
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def show_component_versions(self, component: str, identifier: str): """ Show all versions of a component in the metadata store. :param component: type of component :param identifier: identifier of component """ t = self.db[component] return t.filter(t['identifier...
Show all versions of a component in the metadata store. :param component: type of component :param identifier: identifier of component
show_component_versions
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_uuid(self, component: str, identifier: str, version: int): """ Get the UUID of a component version. :param component: type of component :param identifier: identifier of component :param version: version of component """ t = self.db[component] r = ...
Get the UUID of a component version. :param component: type of component :param identifier: identifier of component :param version: version of component
get_uuid
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def component_version_has_parents( self, component: str, identifier: str, version: int ): """ Check if a component version has parents. :param component: type of component :param identifier: identifier of component :param version: version of component """ ...
Check if a component version has parents. :param component: type of component :param identifier: identifier of component :param version: version of component
component_version_has_parents
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_latest_version( self, component: str, identifier: str, allow_hidden: bool = False ): """ Get the latest version of a component. :param component: type of component :param identifier: identifier of component :param allow_hidden: whether to allow hidden compone...
Get the latest version of a component. :param component: type of component :param identifier: identifier of component :param allow_hidden: whether to allow hidden components
get_latest_version
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_latest_versions(self): """Get the latest versions of a component.""" components = self.show_components() out = [] for component in components: t = self.db[component['component']] q = t.filter(t['identifier'] == component['identifier']).select( ...
Get the latest versions of a component.
get_latest_versions
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_component_by_uuid(self, component: str, uuid: str): """Get a component by UUID. :param component: type of component :param uuid: UUID of component """ r = None if r is None: r = self.db[component].get(uuid=uuid, raw=True) if r is None: ...
Get a component by UUID. :param component: type of component :param uuid: UUID of component
get_component_by_uuid
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_component( self, component: str, identifier: str, version: t.Optional[int] = None, ) -> t.Dict[str, t.Any]: """ Get a component from the metadata store. :param component: type of component :param identifier: identifier of component :pa...
Get a component from the metadata store. :param component: type of component :param identifier: identifier of component :param version: version of component
get_component
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_component_parents(self, component: str, identifier: str): """ Get the parents of a component. :param component: type of component :param identifier: identifier of component """ t = self.db['ParentChildAssociations'] q = t.filter( t['child_comp...
Get the parents of a component. :param component: type of component :param identifier: identifier of component
get_component_parents
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def get_component_version_parents(self, uuid: str): """ Get the parents of a component version. :param uuid: unique identifier of component version """ t = self.db['ParentChildAssociations'] q = t.filter(t['child_uuid'] == uuid).select('parent_component', 'parent_uuid') ...
Get the parents of a component version. :param uuid: unique identifier of component version
get_component_version_parents
python
superduper-io/superduper
superduper/base/metadata.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/metadata.py
Apache-2.0
def bind(f): """Bind a method to a query object. :param f: The method to bind. """ @functools.wraps(f) def decorated(self, *args, **kwargs): out = f(self, *args, **kwargs) children = self.mapping[f.__name__] for method in children: out._bind_base_method(method, ...
Bind a method to a query object. :param f: The method to bind.
bind
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def insert(self: 'Query', documents, raw: bool = False): """Insert documents into the table. # noqa """ # FIXME: Access to a protected member _do_insert of a class out = self.db.databackend.do_insert(self.table, documents, raw=raw) self.db._post_query(self.table, ids=out, type_='insert') re...
Insert documents into the table. # noqa
insert
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def update(self, condition: t.Dict, key: str, value: t.Any): """Update documents in the table. # noqa """ db = route_db(self.db, self.table) s = self.db.metadata.get_schema(self.table) datatype = None if isinstance(s[key], BaseDataType): datatype = s[key] out = db.databackend.do...
Update documents in the table. # noqa
update
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def outputs(self, *predict_ids): """Add outputs to the query. # noqa :param predict_ids: The predict_ids to add. # noqa """ d: Decomposition = self.decomposition assert not d.outputs d.outputs = QueryPart('outputs', predict_ids, {}) return d.to_query()
Add outputs to the query. # noqa :param predict_ids: The predict_ids to add. # noqa
outputs
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def get(self, raw: bool = False, decode: bool = False, **kwargs): """Get a single row of data. # noqa """ query = self if kwargs: filters = [] t = self.db[self.table] for k, v in kwargs.items(): filters.append(t[k] == v) query = self.filter(*filters) ...
Get a single row of data. # noqa
get
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def ids(self): """Get the primary ids of the query. # noqa """ msg = '.ids only applicable to select queries' assert self.type == 'select', msg q = self.select(self.primary_id) pid = self.primary_id.execute() results = q.execute() return [str(r[pid]) for r in results]
Get the primary ids of the query. # noqa
ids
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def distinct(self, key: str): """Get distinct values of a column. # noqa """ q = self.select(key) msg = '.distinct only applicable to select queries' assert self.type == 'select', msg q = self.select(key) results = q.execute() return list(set([r[key] for r in results]))
Get distinct values of a column. # noqa
distinct
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def chunks(self, n: int): """Split a query into chunks of size n. # noqa :param n: The size of the chunks. """ assert self.type == 'select' t = self.db[self.table] ids = self.select(t.primary_id).execute() for i in range(0, len(ids), n): yield self.subset(ids[i : i + n])
Split a query into chunks of size n. # noqa :param n: The size of the chunks.
chunks
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def select(self, *cols): """Create a select query selecting certain fields/ cols. # noqa :param cols: The columns to select. >>> from superduper import superduper >>> db = superduper() >>> db['table'].insert({'col': 1, 'other': 2}) >>> results = db['table'].select('col').execute() >>>...
Create a select query selecting certain fields/ cols. # noqa :param cols: The columns to select. >>> from superduper import superduper >>> db = superduper() >>> db['table'].insert({'col': 1, 'other': 2}) >>> results = db['table'].select('col').execute() >>> list(results[0].keys()) ['c...
select
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def filter(self, *filters): """Create a filter query. # noqa :param filters: The filters to apply. >>> from superduper import superduper >>> db = superduper() >>> t = db['table'] >>> t.insert({'col': 1}) >>> results = t.filter(t['col'] == 1, t['col'] > 0).execute() >>> len(results...
Create a filter query. # noqa :param filters: The filters to apply. >>> from superduper import superduper >>> db = superduper() >>> t = db['table'] >>> t.insert({'col': 1}) >>> results = t.filter(t['col'] == 1, t['col'] > 0).execute() >>> len(results) 1
filter
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def stringify(self, documents, queries): """Stringify the query. :param documents: The documents to stringify. :param queries: The queries to stringify. """ parts = [] for part in self.parts: if isinstance(part, str): if part == 'primary_id': ...
Stringify the query. :param documents: The documents to stringify. :param queries: The queries to stringify.
stringify
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def tables(self): """Tables contained in the ``Query`` object.""" out = [] for part in self.parts: if part.name == 'outputs': out.extend([f'{CFG.output_prefix}{x}' for x in part.args]) out.append(self.table) return list(set(out))
Tables contained in the ``Query`` object.
tables
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def dict(self, *args, **kwargs): """Return the query as a dictionary. :param args: Additional arguments. :param kwargs: Additional keyword arguments. """ documents = [] queries = [] _stringify(self, documents=documents, queries=queries) query = '\n'.join(...
Return the query as a dictionary. :param args: Additional arguments. :param kwargs: Additional keyword arguments.
dict
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def subset(self, ids: t.Sequence[str]): """Subset the query based on primary ids. :param ids: The primary ids to subset on. """ assert self.type == 'select' # mypy nonsense from superduper.base.datalayer import Datalayer assert isinstance(self.db, Datalayer) ...
Subset the query based on primary ids. :param ids: The primary ids to subset on.
subset
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def execute(self, raw: bool = False, decode: bool = False): """Execute the query. :param raw: Whether to return raw results. :param decode: Whether to decode the results. """ db = route_db(self.db, self.table) # type: ignore if self.parts and self.parts[0] == 'primary_i...
Execute the query. :param raw: Whether to return raw results. :param decode: Whether to decode the results.
execute
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def parse_query( query: t.Union[str, list], documents: t.Sequence[t.Any] = (), db: t.Optional['Datalayer'] = None, ): """Parse a string query into a query object. :param query: The query to parse. :param documents: The documents to query. :param db: The datalayer to use to execute the query...
Parse a string query into a query object. :param query: The query to parse. :param documents: The documents to query. :param db: The datalayer to use to execute the query.
parse_query
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def route_db(db: "Datalayer", table) -> "Datalayer": """Route the database to the correct datalayer. :param db: The datalayer to use. :param table: The table to use. """ assert db is not None if db.metadata.check_table_in_metadata(table): db = db.metadata.db return db
Route the database to the correct datalayer. :param db: The datalayer to use. :param table: The table to use.
route_db
python
superduper-io/superduper
superduper/base/query.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/query.py
Apache-2.0
def parse(spec): """Parse a schema from a string. :param spec: The string to parse. """ parts = dict([tuple(x.strip().split('=')) for x in spec.split('|')]) fields = {k: INBUILT_DATATYPES[v] for k, v in parts.items()} return Schema(fields)
Parse a schema from a string. :param spec: The string to parse.
parse
python
superduper-io/superduper
superduper/base/schema.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/schema.py
Apache-2.0
def build(**fields: t.Dict[str, str]) -> 'Schema': """Build a schema from a dictionary of fields. :param fields: The fields of the schema # noqa """ from superduper.base.datatype import INBUILT_DATATYPES fields = {k: INBUILT_DATATYPES[fields[k]] for k in fields} ...
Build a schema from a dictionary of fields. :param fields: The fields of the schema # noqa
build
python
superduper-io/superduper
superduper/base/schema.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/schema.py
Apache-2.0
def trivial(self): """Determine if the schema contains only trivial fields.""" return not any( [isreallyinstance(v, BaseDataType) for v in self.fields.values()] )
Determine if the schema contains only trivial fields.
trivial
python
superduper-io/superduper
superduper/base/schema.py
https://github.com/superduper-io/superduper/blob/master/superduper/base/schema.py
Apache-2.0