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

_rng(→ random.Random)

Build a process-stable RNG from seed parts.

replay_state(→ tuple[list[int], dict[int, int], int])

Replay batches 1..batch-1 and return live ids, versions, and high-water mark.

select_batch_ids(→ tuple[list[int], list[int], list[int]])

Deterministically pick insert, update, and noop ids for a batch.

build_batch_rows(→ tuple[pandas.DataFrame, ...)

Build the ordered row set for a batch: inserts, updates, noops.

_build_rows(→ pandas.DataFrame)

Materialize a DataFrame from ids, versions, and ops.

_cell(→ Any)

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.Random instance 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-1 and 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.

  • batch0 for the full load, >= 1 for 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_column is 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. 0 reproduces the original value.

Returns:

A scalar cell value.

Raises:

ReadError – If the column kind is unknown.