Diff Two Daily Snapshots Into Inserts Updates and Deletes
Last updated: November 29, 2026
Quick Overview
A Meta advertiser dimension is delivered as a full daily snapshot. Compare today's snapshot to yesterday's and classify each advertiser as inserted, updated, deleted, or unchanged, ready to apply as a MERGE into a slowly changing dimension.
Meta
November 29, 20260
0
0 solved
A Meta advertiser dimension is delivered as a full daily snapshot. Compare today's snapshot to yesterday's and classify each advertiser as inserted, updated, deleted, or unchanged, ready to apply as a MERGE into a slowly changing dimension.
Meta data engineers maintain many dimensions built from upstream snapshots, and onsite rounds ask how to compute changes efficiently. The interviewer checks a full outer join on the business key, NULL-safe comparison of attributes, and deduping a snapshot that has duplicate keys.
What the Interviewer Expects
- Dedupes each snapshot to one row per key before comparing
- FULL OUTER JOINs on the business key
- Uses NULL-safe comparison (IS DISTINCT FROM) or a row hash
- Classifies rows into four change types
- Explains how to apply the result to an SCD type 2 table
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- Why can a hash of concatenated columns produce false matches?
- How would you handle late-arriving snapshots?
- What if the snapshot is partial on some days?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
adv_snapshot(ds, advertiser_id, name, country, vertical, status). Upstream occasionally emits two rows for the same advertiser on one day; I keep the one with the latest updated_at. Attributes can...
Approach
- Dedupe both days to one row per advertiser.
- FULL OUTER JOIN today (t) and yesterday (y) on advertiser_id.
- Classify: y missing means insert; t missing means delete; any attribute `IS DISTINCT ...