Load new and changed records safely
A dispatch fact may arrive after midnight and be corrected a day later.
Load new and changed records safely
A dispatch fact may arrive after midnight and be corrected a day later. An event-time watermark alone would miss that correction. Capture a trustworthy change position or overlap the previous interval and merge by business key and source version. Commit the destination before advancing the checkpoint. Record an explicit policy for facts whose dimension member has yet to arrive.
Decisions to rehearse
- Change-position checkpoint
- A source change position captures updates even when the business event happened earlier.
- Version-aware merge
- A keyed merge with a source sequence prevents duplicates and an old replay overwriting newer state.
- Type 2 dimension
- A versioned dimension preserves attributes and their validity intervals for historical joins.
- Inferred or unknown dimension member
- An explicit placeholder allows the fact to load while preserving a way to resolve the missing dimension later.
- Full refresh
- Rebuilding from a complete authoritative snapshot is reasonable for a small table without change tracking.
- Commit target before advancing the checkpoint
- A checkpoint must describe durable destination state so a failed write remains replayable.
Practise each Microsoft skill
These local references follow the Microsoft bullet order within this skills group.
- 2.1.1 · Compare a full refresh with a change-driven load after an update to a record whose creation date is outside the extract window.
- 2.1.2 · Prepare fact grain, natural keys, surrogate keys and effective dates. Reconcile a fact arriving before its customer dimension.
- 2.1.3 · Choose a streaming checkpoint, event identifier and lateness policy, then simulate a restart before the sink write completes.
Official skills for this topic
Work through the decision
The source changes order A on Friday, but A still carries Tuesday's sale timestamp. A load filters only on event date. How can the engineer prove corrections will reach the target?
Check your reasoning
Use a trustworthy change position or a bounded overlap plus reconciliation. Merge only newer source revisions and replay the same input after a simulated failure. Check both row count and final value.
Recover after a failed incremental load
31:26 · Change detection and watermarks. Identify what information the cursor must retain, then use the lab to test a failure between reading the source and committing the target.
Run a simulated write followed by a crash before checkpointing. Predict the checkpoint, target and retry result. Change the predicate so an older revision can overwrite a newer one and observe the regression. Run with Python 3 and its standard library.
import sqlite3
db = sqlite3.connect(":memory:")
db.executescript("""
CREATE TABLE target (id TEXT PRIMARY KEY, revision INTEGER, amount INTEGER);
CREATE TABLE cursor_state (position INTEGER);
INSERT INTO cursor_state VALUES (0);
""")
changes = [(1, "A", 2, 15), (2, "A", 1, 10), (3, "B", 1, 7)]
def load(fail):
position, = db.execute("SELECT position FROM cursor_state").fetchone()
with db:
for sequence, key, revision, amount in changes:
if sequence > position:
db.execute("""
INSERT INTO target VALUES (?, ?, ?)
ON CONFLICT(id) DO UPDATE SET revision=excluded.revision, amount=excluded.amount
WHERE excluded.revision > target.revision
""", (key, revision, amount))
if fail:
raise RuntimeError("interrupted")
db.execute("UPDATE cursor_state SET position=?", (changes[-1][0],))
try:
load(True)
except RuntimeError:
print("checkpoint after failure:", db.execute("SELECT position FROM cursor_state").fetchone()[0])
load(False)
load(False)
print(list(db.execute("SELECT * FROM target ORDER BY id")))
Check the result
checkpoint after failure: 0
[('A', 2, 15), ('B', 1, 7)]The transaction rolls back the incomplete run. The later source position carrying an older business revision cannot overwrite A. In Fabric, where a source checkpoint and destination may not share a transaction, commit an idempotent destination write before advancing the cursor.
Related lesson in AWS Data Engineer – Associate · Capture a feed you can replay.
Load new and changed records safely quiz
Answer 3 questions. Check each answer for an explanation.