ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark =================================================================== .. py:module:: ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark .. autoapi-nested-parse:: **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 ---------- .. autoapisummary:: ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._CHECKPOINT_KEY ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._WATERMARK_KEY ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._PENDING_KEY ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._ISO_DATE Classes ------- .. autoapisummary:: ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark.WatermarkRules Functions --------- .. autoapisummary:: ds_protocol_graphql_py_lib.dataset.incremental.strategies.watermark._comparable Module Contents --------------- .. py:data:: _CHECKPOINT_KEY :value: 'incremental' .. py:data:: _WATERMARK_KEY :value: 'watermark' .. py:data:: _PENDING_KEY :value: 'pending' .. py:data:: _ISO_DATE .. py:function:: _comparable(value: Any) -> Any Sort key: ISO date strings become ``pd.Timestamp``; anything else is compared as is. .. py:class:: WatermarkRules Bases: :py:obj:`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. .. py:method:: 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 Apply persisted state (the stored watermark) to the base request. .. py:method:: observe(checkpoint: dict[str, Any], page: pandas.DataFrame, settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings | None) -> None 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. .. py:method:: commit(checkpoint: dict[str, Any], output: pandas.DataFrame, settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings | None) -> None Advance persisted state after a fully successful drain. Does not clear ``checkpoint["pagination"]`` — that is owned by Paginate. .. py:method:: _slice(checkpoint: dict[str, Any]) -> dict[str, Any] :staticmethod: .. py:method:: _stored(slice_: dict[str, Any], key: str) -> list[Any] :staticmethod: .. py:method:: _values(frame: pandas.DataFrame, settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings) -> list[Any] :classmethod: .. py:method:: _max(values: list[Any], settings: ds_protocol_graphql_py_lib.dataset.incremental.settings.IncrementalSettings) -> Any :staticmethod: Max of ``values``, comparing ISO date strings as instants. .. py:method:: _to_stored(value: Any) -> Any :staticmethod: ``pd.Timestamp`` → ISO string so the checkpoint stays JSON-serialisable. .. py:method:: _is_missing_scalar(value: Any) -> bool :staticmethod: True for ``None`` and pandas-missing scalars (``NaN``, ``NaT``, ``NA``).