task Deduplication · medium
Audit conflicting event retries
Report only retried event keys. Return event_key, the smallest id as canonical_id, the event_type from that canonical row as canonical_type, and the number of additional ingestion rows as retry_count.
what to return
- Columns
event_keycanonical_idcanonical_typeretry_countin this order- Rows
- 2 rows · in the order asked
- Watch for
- Deduplicate globally by event_key, keeping the smallest id; a retry may have a conflicting payload.
- Use (occurred_at, id) as the total event order; equal timestamps follow id order. All times are UTC.
- Count all retry rows even when their payload differs. Order by event_key.
- Skill
- Separate logical event identity from ingestion row identity. Refresher: Sessionize an event stream →
expected result
Your query should return exactly these columns and values. Run it and compare.
expected result2 rows · in this order
| event_key | canonical_id | canonical_type | retry_count |
|---|---|---|---|
| a3 | 3 | purchase | 1 |
| i3 | 28 | purchase | 1 |
all 2 rows
data you can query
Sample rows from each table. Each column shows its type underneath; → marks a link to another table.
market_web_events7 columns · 38 rows
| idinteger · key | event_keytext | shopper_idinteger → shoppers | occurred_attext | event_typetext | channeltext | cart_idtext |
|---|---|---|---|---|---|---|
| 1 | a1 | 1 | 2025-05-01 09:00:00 | view | A | |
| 2 | a2 | 1 | 2025-05-01 09:05:00 | checkout | direct | A |
| 3 | a3 | 1 | 2025-05-01 09:10:00 | purchase | direct | A |
| 4 | a3 | 1 | 2025-05-01 09:10:00 | purchase | direct | A |
| 5 | b1 | 1 | 2025-05-01 10:00:00 | view | search | B |
showing 5 of 38 rows
solution.sql
Hints and the answer are always available. Using them counts the question as solved with help.