A Lakeflow declarative pipeline consumes a CDC feed of inserts, updates, and deletes keyed by customer_id, and events sometimes arrive out of order. The target table must always reflect the latest state per key. Which approach correctly applies the changes?
Answer & explanation
Correct answer: A
WHY A: AUTO CDC / APPLY CHANGES INTO applies inserts, updates, and deletes by KEYS and uses SEQUENCE BY to order events, so out-of-order changes resolve to the latest state per key automatically.
WHY NOT B: A declarative pipeline supports keyed upserts natively via AUTO CDC / APPLY CHANGES INTO, so hand-written foreachBatch MERGE code is unnecessary.
WHY NOT C: Appending every CDC event to a streaming table keeps duplicates and deletes as rows rather than maintaining the current state per key in the target.
WHY NOT D: CREATE OR REPLACE overwrites the target and is expensive, and it discards history rather than applying changes incrementally.
WHY NOT E: Omitting SEQUENCE BY relies on arrival order, so an out-of-order event can apply an older update over a newer one.