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 a JSON string to a watermark dict.
get_watermark
abstractmethod
¶
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.
validate_ready
¶
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
¶
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 |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Watermark dictionary. |
serialize
staticmethod
¶
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
¶
Convenience wrapper for :meth:WatermarkSerializer.serialize.
deserialize_watermark
¶
Convenience wrapper for :meth:WatermarkSerializer.deserialize.
is_watermark_empty
¶
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
¶
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.