Skip to content

Watermark

ETL manager contract

When an ETL execution receives a watermark manager, the manager must provide callable get_watermark, save_watermark, and serialize methods. The orchestrator validates those capabilities before reading persisted state. Source readers own merge semantics through BaseSourceReader.validate_watermark(value, *, boundary=...) and BaseSourceReader.merge_watermark(existing, candidate: WatermarkCandidate | None) -> dict. Serialization is performed before the destination write, so invalid watermark values cannot leave a successful target mutation without a saveable state.

WatermarkRuntimeInfo is the canonical per-attempt evidence model. It keeps provider load status, loaded value, merge base, typed candidate, prepared save payload, and save acknowledgement separate. A source result with no rows skips transform, write, and save—even for bounded replay—and retains any candidate with save_status="not_attempted"; a transformed-empty frame is still passed to the destination writer.

WatermarkCandidate stores the pure {values, kind} observation returned by a source. Candidate kinds are observed_max, request_end, opaque, and metadata. Load status is not_requested, loaded, reused, or load_error; save status is not_requested, not_attempted, no_candidate, saved, or save_error.

contracts

Typed watermark value and status contracts.

WatermarkCandidateKind

Bases: str, Enum

Source-owned meaning of a watermark candidate.

WatermarkLoadStatus

Bases: str, Enum

Provider-load outcome for one attempt.

WatermarkSaveStatus

Bases: str, Enum

Provider-save outcome for one attempt.

WatermarkCandidate dataclass

WatermarkCandidate(
    values: dict[str, Any], kind: WatermarkCandidateKind
)

Pure source observation returned with a successful read.

runtime

Per-attempt watermark runtime evidence.

WatermarkRuntimeInfo dataclass

WatermarkRuntimeInfo(
    load_status: WatermarkLoadStatus = NOT_REQUESTED,
    loaded_watermark: dict[str, Any] | None = None,
    merge_base: dict[str, Any] | None = None,
    candidate: WatermarkCandidate | None = None,
    watermark_to_save: dict[str, Any] | None = None,
    save_status: WatermarkSaveStatus = NOT_REQUESTED,
    saved_watermark: dict[str, Any] | None = None,
)

Provider and source watermark evidence kept separate by phase.

base

Watermark serialization and abstract manager.

WatermarkSerializer converts Dict[str, Any] watermarks to/from JSON using the __datetime__ sentinel pattern for datetime round-tripping.

BaseWatermarkManager is the ABC that :class:WatermarkManager implements.

BaseWatermarkManager

Bases: ABC

Abstract watermark manager.

Concrete implementations decide where watermarks are stored (file, database, API). The serializer is an internal concern — callers always pass and receive Dict[str, Any].

deserialize

deserialize(json_str: str) -> Dict[str, Any]

Deserialize a JSON string to a watermark dict.

get_watermark abstractmethod

get_watermark(dataflow_id: str) -> Optional[Dict[str, Any]]

Return the current watermark for dataflow_id, or None.

save_watermark abstractmethod

save_watermark(
    dataflow_id: str,
    watermark: Dict[str, Any],
    *,
    job_id: Optional[str] = None,
    dataflow_run_id: Optional[str] = None,
) -> None

Persist a watermark for dataflow_id.

serialize

serialize(watermark: Dict[str, Any]) -> str

Serialize a dict watermark to JSON.

validate_ready

validate_ready() -> None

Validate configuration without reading or writing watermark state.

WatermarkSerializer

Serialize / deserialize watermark dictionaries to / from JSON.

datetime values are stored as::

{"__datetime__": "2026-02-09T10:30:00+00:00"}

and restored on deserialization.

deserialize staticmethod

deserialize(json_str: Optional[str]) -> Dict[str, Any]

Parse a JSON string back into a watermark dict.

Restores __datetime__ patterns to datetime objects. Empty / null inputs return {}. A non-empty malformed value is corruption and raises :class:WatermarkError; it must not be treated as an absent first-run checkpoint.

Parameters:

Name Type Description Default
json_str Optional[str]

JSON string (may be None, empty, "null").

required

Returns:

Type Description
Dict[str, Any]

Watermark dictionary.

serialize staticmethod

serialize(watermark: Dict[str, Any]) -> str

Convert a watermark dict to a JSON string.

datetime values are encoded with the __datetime__ pattern.

Parameters:

Name Type Description Default
watermark Dict[str, Any]

Watermark key-value pairs.

required

Returns:

Type Description
str

JSON string.

serialize_watermark

serialize_watermark(watermark: Dict[str, Any]) -> str

Convenience wrapper for :meth:WatermarkSerializer.serialize.

deserialize_watermark

deserialize_watermark(json_str: str) -> Dict[str, Any]

Convenience wrapper for :meth:WatermarkSerializer.deserialize.

is_watermark_empty

is_watermark_empty(
    watermark: Optional[Dict[str, Any]],
) -> bool

Return True if the watermark is None, empty, or all-None values.

watermark_manager

Concrete watermark manager that delegates storage to a metadata provider.

WatermarkManager is the primary implementation used by the ETL Driver. It serializes / deserializes watermarks and delegates persistence to the injected :class:~datacoolie.metadata.base.BaseMetadataProvider.

For file-based standalone operation, FileProvider implements both metadata and watermark storage, so WatermarkManager simply delegates save/get through the same provider.

WatermarkManager

WatermarkManager(metadata_provider: BaseMetadataProvider)

Bases: BaseWatermarkManager

Watermark manager backed by a metadata provider.

Parameters:

Name Type Description Default
metadata_provider BaseMetadataProvider

Provider responsible for watermark persistence.

required

get_watermark

get_watermark(dataflow_id: str) -> Optional[Dict[str, Any]]

Return the current watermark dict, or None.

save_watermark

save_watermark(
    dataflow_id: str,
    watermark: Dict[str, Any],
    *,
    job_id: Optional[str] = None,
    dataflow_run_id: Optional[str] = None,
) -> None

Serialize the source-merged watermark and persist via the provider.

Ordering and replacement semantics belong to the source reader that produced the observation. The orchestration pipeline performs that merge before calling this method; the manager deliberately remains a codec and storage boundary so a second generic merge cannot override a reader's contract or race with a second state read.