ds_provider_mock_py_lib.dataset.engines._read_rows¶
File: _read_rows.py
Region: ds_provider_mock_py_lib/dataset/engines
Deterministic batch generation for mock reads.
Every id selection and cell value is a pure function of
(settings.seed, id, version, batch). No hidden process state is used, so
reconnects and suite reruns produce the same rows.
Example
>>> from ds_provider_mock_py_lib.dataset.engines._read_rows import build_batch_rows
>>> from ds_provider_mock_py_lib.dataset.settings import MockDatasetSettings
>>> frame, ops = build_batch_rows(settings=MockDatasetSettings(row_count=3), batch=0)
>>> [op.value for op in ops]
['insert', 'insert', 'insert']
>>> "_op" in frame.columns
False
Functions¶
|
Build a process-stable RNG from seed parts. |
|
Replay batches |
|
Deterministically pick insert, update, and noop ids for a batch. |
|
Build the ordered row set for a batch: inserts, updates, noops. |
|
Materialize a DataFrame from ids, versions, and ops. |
|
Compute one cell value as a pure function of seed, column, id, and version. |
Module Contents¶
- ds_provider_mock_py_lib.dataset.engines._read_rows._rng(*parts: int | str) random.Random[source]¶
Build a process-stable RNG from seed parts.
- Parameters:
parts – Values mixed into the SHA-256 seed.
- Returns:
A
random.Randominstance with a stable seed.
- ds_provider_mock_py_lib.dataset.engines._read_rows.replay_state(settings: ds_provider_mock_py_lib.dataset.settings.MockDatasetSettings, batch: int) tuple[list[int], dict[int, int], int][source]¶
Replay batches
1..batch-1and return live ids, versions, and high-water mark.- Parameters:
settings – Dataset settings that define batch composition.
batch – Batch about to be generated.
- Returns:
(live_ids, id_to_version, high_water_mark).
- ds_provider_mock_py_lib.dataset.engines._read_rows.select_batch_ids(settings: ds_provider_mock_py_lib.dataset.settings.MockDatasetSettings, batch: int, live: list[int], high_water_mark: int) tuple[list[int], list[int], list[int]][source]¶
Deterministically pick insert, update, and noop ids for a batch.
- Parameters:
settings – Dataset settings that define batch composition.
batch – Batch number being generated.
live – Currently live ids.
high_water_mark – Next unused id.
- Returns:
(inserts, updates, noops).- Raises:
ReadError – If the batch needs more live rows than exist.
- ds_provider_mock_py_lib.dataset.engines._read_rows.build_batch_rows(settings: ds_provider_mock_py_lib.dataset.settings.MockDatasetSettings, batch: int) tuple[pandas.DataFrame, list[ds_provider_mock_py_lib.enums.RowOp]][source]¶
Build the ordered row set for a batch: inserts, updates, noops.
Insert adds a new primary key. Update reuses a live key with changed values so the row hash changes. Noop reuses a live key with the same values so the row hash is unchanged.
- Parameters:
settings – Dataset settings that define columns and batch composition.
batch –
0for the full load,>= 1for an incremental change batch.
- Returns:
The batch DataFrame and a parallel list of intended row kinds.
- ds_provider_mock_py_lib.dataset.engines._read_rows._build_rows(settings: ds_provider_mock_py_lib.dataset.settings.MockDatasetSettings, ids: list[int], versions: dict[int, int], ops: list[ds_provider_mock_py_lib.enums.RowOp]) pandas.DataFrame[source]¶
Materialize a DataFrame from ids, versions, and ops.
- Parameters:
settings – Dataset settings that define columns.
ids – Row identities in emission order.
versions – Last insert/update batch per id.
ops – Change-tracking operation per emitted row.
- Returns:
A DataFrame of configured columns plus
modified_at.op_columnis included only when explicitly configured.
- ds_provider_mock_py_lib.dataset.engines._read_rows._cell(settings: ds_provider_mock_py_lib.dataset.settings.MockDatasetSettings, column: ds_provider_mock_py_lib.dataset.settings.MockColumn, row_id: int, version: int) Any[source]¶
Compute one cell value as a pure function of seed, column, id, and version.
- Parameters:
settings – Dataset settings containing the determinism seed.
column – Column definition.
row_id – Row identity.
version – Last insert/update batch for this id.
0reproduces the original value.
- Returns:
A scalar cell value.
- Raises:
ReadError – If the column kind is unknown.