ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark

File: watermark.py Region: ds_protocol_graphql_py_lib/dataset/incremental/strategies/watermark

High-watermark incremental ruleset.

Prepare

If checkpoint["incremental"]["watermark"] is set, inject it into the GraphQL variable settings.variable. Otherwise send the request unchanged (first run / full load). pending is never sent.

Observe (every fetched page)

Set checkpoint["incremental"]["pending"] to the max of its current value and the page’s values at watermark_path, so it only ever goes up. The committed watermark does not move. A drain that fails after some pages leaves pending behind, so the resumed drain, which starts after the saved cursor and never sees those pages, still commits their max.

Commit (full success only)

Set the watermark to the max of the previous watermark, pending and the values in this call’s output, and drop pending. The watermark never moves backwards, and an empty resumed tail still promotes pending.

Attributes

_CHECKPOINT_KEY

_WATERMARK_KEY

_PENDING_KEY

_ISO_DATE

Classes

WatermarkRules

Resume on a caller-persisted high-watermark.

Functions

_comparable(→ Any)

Sort key: ISO date strings become pd.Timestamp; anything else is compared as is.

Module Contents

ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._CHECKPOINT_KEY = 'incremental'
ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._WATERMARK_KEY = 'watermark'
ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._PENDING_KEY = 'pending'
ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._ISO_DATE
ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._comparable(value: Any) → Any[source]

Sort key: ISO date strings become pd.Timestamp; anything else is compared as is.

class ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark.WatermarkRules[source]

Bases: ds_protocol_graphql_py_lib.dataset.incremental.rules.IncrementalRules

Resume on a caller-persisted high-watermark.

Reads checkpoint["incremental"]["watermark"] on prepare. Tracks the max value seen so far in checkpoint["incremental"]["pending"] per page, and on commit advances the watermark to the max of the previous watermark, pending and the output rows. Pandas-missing scalars (NaN, NaT, NA) are ignored. Does not clear pagination state — Paginate owns that.

prepare(request: ds_protocol_graphql_py_lib.dataset.request.GraphqlRequestSnapshot, checkpoint: dict[str, Any], settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings | None) → ds_protocol_graphql_py_lib.dataset.request.GraphqlRequestSnapshot[source]

Apply persisted state (the stored watermark) to the base request.

observe(checkpoint: dict[str, Any], page: pandas.DataFrame, settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings | None) → None[source]

Record state from each fetched page for a later commit.

Never write the watermark prepare sends; use a separate checkpoint key (e.g. pending), so a resumed drain keeps the same lower bound.

commit(checkpoint: dict[str, Any], output: pandas.DataFrame, settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings | None) → None[source]

Advance persisted state after a fully successful drain.

Does not clear checkpoint["pagination"] — that is owned by Paginate.

static _slice(checkpoint: dict[str, Any]) → dict[str, Any][source]
static _stored(slice_: dict[str, Any], key: str) → list[Any][source]
classmethod _values(frame: pandas.DataFrame, settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings) → list[Any][source]
static _max(values: list[Any], settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings) → Any[source]

Max of values, comparing ISO date strings as instants.

static _to_stored(value: Any) → Any[source]

pd.Timestamp → ISO string so the checkpoint stays JSON-serialisable.

static _is_missing_scalar(value: Any) → bool[source]

True for None and pandas-missing scalars (NaN, NaT, NA).