feat(elt-common): Watermark (de)serializiation - #347
Conversation
ref #321 Co-authored-by: Martyn Gigg <martyn.gigg@gmail.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR extends the ChangesWatermark serialization and validation
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
elt-common/src/elt_common/extract.py (1)
32-36: 💤 Low valueConsider using
isinstance()for type checks.Whilst
type(column) is not strandtype(value) not in (str, int, float)work correctly for JSON-deserialised primitives, usingisinstance()would be more idiomatic Python and handle subclasses gracefully.♻️ Proposed refactor
column = as_json["column"] - if type(column) is not str: + if not isinstance(column, str): raise ValueError(f"Watermark 'column' must be a string, '{column}' is not valid") value = as_json["value"] - if type(value) not in (str, int, float): + if not isinstance(value, (str, int, float)): raise ValueError( f"Watermark 'value' must be a string or number, '{value}' is not valid" )🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@elt-common/src/elt_common/extract.py` around lines 32 - 36, Replace the strict type() checks for the watermark fields with idiomatic isinstance() checks: in the block handling as_json["column"] and as_json["value"] (variables column and value in elt_common.extract), use isinstance(column, str) and isinstance(value, (str, int, float)) respectively; update the ValueError conditions to trigger when these isinstance checks fail so subclasses are handled correctly while preserving the original error messages and behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@elt-common/src/elt_common/extract.py`:
- Around line 16-17: Add an explicit return type annotation to the serialize
method: change the signature of serialize to include "-> str" (i.e., def
serialize(self) -> str:) so the method explicitly returns a string; ensure any
related type hints or linters accept this change and leave the existing
implementation (json.dumps(...)) unchanged.
- Around line 20-41: The deserialize function lacks an explicit return type;
update its signature for clarity and typing by adding "-> Watermark" to the
deserialize(...) definition (the function that parses JSON and returns a
Watermark instance), ensure the Watermark symbol is imported/available in the
module so the annotation resolves correctly, and run type checks to confirm no
other type errors are introduced.
---
Nitpick comments:
In `@elt-common/src/elt_common/extract.py`:
- Around line 32-36: Replace the strict type() checks for the watermark fields
with idiomatic isinstance() checks: in the block handling as_json["column"] and
as_json["value"] (variables column and value in elt_common.extract), use
isinstance(column, str) and isinstance(value, (str, int, float)) respectively;
update the ValueError conditions to trigger when these isinstance checks fail so
subclasses are handled correctly while preserving the original error messages
and behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c26d3379-88c8-4756-ac7b-cb7488eee653
📒 Files selected for processing (2)
elt-common/src/elt_common/extract.pyelt-common/tests/unit_tests/test_extract.py
martyngigg
left a comment
There was a problem hiding this comment.
I'm happy with moving the serialize/deserialize methods to Watermark. When I was originally playing with it I didn't use JSON and thought custom ingestion scripts might need to provide there own implementation but JSON should be flexible enough to encode what we need and then the extractor path can do with the value what it wants.
ref #321
Adds functionality for (de)serializing watermarks from/to JSON, to be read/written from/to iceberg properties.
Compared with
elt-command-without-dlt, I've removed the abstraction ofWatermarkSerializationto simplify the code a little. There was only a single implementation, and I don't think we'll need others(?), so seemed like a case of YAGNI.Also combines
WriteModedefinitions as mentioned here.Summary by CodeRabbit