A CDC feed gives you every change to a table. Before it can be merged into the warehouse it has to be collapsed to one row per key — what the table looks like now, not how it got there.
changes — a list of (key, version, op, payload) - key — str - version — int, unique within a key and increasing with time - op — 'UPSERT' or 'DELETE' - payload — str, and None on a deleteThe list is not in version order. A feed that replays, or that merges two partitions, delivers rows in whatever order they were read.
A list of (key, payload) for every key whose newest change is an UPSERT. Order is not graded.
version, not the last row in the list.DELETE does not appear at all. It does not fall back to the value before the delete.changes[ ["a", 1, "UPSERT", "a1"], ["a", 2, "UPSERT", "a2"], ["b", 1, "UPSERT", "b1"] ]
[["a", "a2"], ["b", "b1"]]
changes[ ["a", 1, "UPSERT", "a1"], ["a", 2, "DELETE", null], ["b", 1, "UPSERT", "b1"] ]
[["b", "b1"]]
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.