openclean.data.archive.histore module
Implementation of the data store that is based on HISTORE. For each dataset a new HISTORE archive will be maintained. This archive is augmented with storage of dataset metadata.
- class openclean.data.archive.histore.HISTOREDatastore(archive: histore.archive.base.Archive, metastore: Optional[openclean.data.metadata.base.MetadataStoreFactory] = None)
Bases:
openclean.data.archive.base.ArchiveStore
Data store implementation that is based on HISTORE. This class is a simple wrapper around a HISTORE archive.
- apply(operators: Union[histore.document.operator.DatasetOperator, List[histore.document.operator.DatasetOperator]], origin: Optional[int] = None, validate: Optional[bool] = None) List[histore.archive.snapshot.Snapshot]
Apply a given operator or a sequence of operators on a snapshot in the archive.
The resulting snapshot(s) will directly be merged into the archive. This method allows to update data in an archive directly without the need to checkout the snapshot first and then commit the modified version(s).
Returns list of handles for the created snapshots.
Note that there are some limitations for this method. Most importantly, the order of rows cannot be modified and neither can it insert new rows at this point. Columns can be added, moved, renamed, and deleted.
- Parameters
operators (histore.document.operator.DatasetOperator or) – list of histore.document.stream.DatasetOperator Operator(s) that is/are used to update the rows in a dataset snapshot to create new snapshot(s) in this archive.
origin (int, default=None) – Unique version identifier for the original snapshot that is being updated. By default the last version is updated.
validate (bool, default=False) – Validate that the resulting archive is in proper order before committing the action.
- Return type
histore.archive.snapshot.Snapshot
- checkout(version: Optional[int] = None) pandas.core.frame.DataFrame
Get a specific dataset snapshot. The snapshot is identified by the unique version identifier.
Raises a ValueError if the given version is unknown.
- Parameters
version (int) – Unique dataset version identifier.
- Return type
pd.DataFrame
- Raises
ValueError –
- commit(source: Union[pandas.core.frame.DataFrame, str, histore.document.base.Document], action: Optional[openclean.data.archive.base.ActionHandle] = None, checkout: Optional[bool] = False) Union[pandas.core.frame.DataFrame, str, histore.document.base.Document]
Insert a new version for a dataset.
Returns the inserted data frame. If the
checkout
flag is True the commited dataset is checked out to account for possible changes to the row index. If the flag is set to False the given data frame is returned.- Parameters
source (openclean.data.stream.base.Datasource) – Input data frame or stream containing the new dataset version that is being stored.
action (openclean.data.archive.base.ActionHandle, default=None) – Optional handle of the action that created the new dataset version.
checkout (bool, default=False) – Checkout the commited snapshot and return the result. This option is required only if the row index of the given data frame has been modified by the commit operation, i.e., if the index of the given data frame contained non-integers, negative values, or duplicate values.
- Return type
openclean.data.stream.base.Datasource
- last_version() int
Get a identifier for the last version of a dataset.
- Return type
int
- metadata(version: Optional[int] = None) openclean.data.metadata.base.MetadataStore
Get metadata that is associated with the referenced dataset version. If no version is specified the metadata collection for the latest version is returned.
Raises a ValueError if the dataset version is unknown.
- Parameters
version (int) – Unique dataset version identifier.
- Return type
- Raises
ValueError –
- open(version: Optional[int] = None) histore.archive.reader.SnapshotReader
Get a stream reader for a dataset snapshot.
- Parameters
version (int, default=None) – Unique version identifier. By default the last version is used.
- Return type
openclean.data.archive.base.SnapshotReader
- rollback(version: int) pandas.core.frame.DataFrame
Rollback the archive history to the snapshot with the given version identifier.
Returns the data frame for the napshot that is now the last snapshot in the modified archive.
- Parameters
version (int) – Unique identifier of the rollback version.
- Return type
pd.DataFrame
- schema() histore.archive.schema.ArchiveSchema
Get the schema history for the archived dataset.
- Return type
openclean.data.archive.base.ArchiveSchema
- snapshots() List[histore.archive.snapshot.Snapshot]
Get list of handles for all versions of a given dataset.
- Return type
list of histore.archive.snapshot.Snapshot