Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Dark-store stock movements reach the warehouse over a flaky network, so every row carries two timestamps: event_at, when the pick or restock happened, and ingested_at, when the warehouse received it. The 5 March closing-stock report was sent on the night of 5 March. Rows have arrived since.
Return the store and sku pairs whose closing stock has changed, ordered by store_id then sku.
Result columns · in this order
store_id | The dark store. |
sku | The product. |
units_on_hand | Closing stock for 5 March on event time. |
late_events | How many of those events arrived after the cutoff. |
How to approach it
Both timestamps are on every row. Decide which one defines the reporting window, and which one flags the problem.
Sample input
| event_id | store_id | sku | event_at | delta_units | ingested_at |
|---|---|---|---|---|---|
| 1 | s1 | MILK-1L | 2026-03-04 06:00:00 | 120 | 2026-03-04 06:00:20 |
| 2 | s1 | MILK-1L | 2026-03-04 09:30:00 | -40 | 2026-03-04 09:30:11 |
| 3 | s1 | MILK-1L | 2026-03-05 07:15:00 | -25 | 2026-03-05 07:15:09 |
| 4 | s1 | MILK-1L | 2026-03-05 18:40:00 | -30 | 2026-03-07 04:05:00 |
| 5 | s1 | BREAD | 2026-03-04 06:05:00 | 60 | 2026-03-04 06:05:14 |
| 6 | s1 | BREAD | 2026-03-05 11:00:00 | -18 | 2026-03-05 11:00:07 |
| 7 | s1 | BREAD | 2026-03-05 21:10:00 | -12 | 2026-03-06 09:20:00 |
| 8 | s2 | MILK-1L | 2026-03-04 05:50:00 | 90 | 2026-03-04 05:50:30 |
| 9 | s2 | MILK-1L | 2026-03-05 08:00:00 | -35 | 2026-03-05 08:00:12 |
| 10 | s2 | MILK-1L | 2026-03-06 07:00:00 | -20 | 2026-03-06 07:00:10 |
| 11 | s2 | EGGS-6 | 2026-03-04 07:00:00 | 48 | 2026-03-04 07:00:22 |
| 12 | s2 | EGGS-6 | 2026-03-05 19:30:00 | -16 | 2026-03-08 02:00:00 |
| 13 | s2 | EGGS-6 | 2026-03-06 10:00:00 | -8 | 2026-03-06 10:00:05 |
| 14 | s3 | BREAD | 2026-03-03 06:00:00 | 40 | 2026-03-03 06:00:18 |
| 15 | s3 | BREAD | 2026-03-05 12:00:00 | -22 | 2026-03-05 12:00:09 |
| 16 | s3 | MILK-1L | 2026-03-04 06:30:00 | 75 | 2026-03-04 06:30:25 |
| 17 | s3 | MILK-1L | 2026-03-05 20:00:00 | -15 | 2026-03-06 15:45:00 |
| 18 | s3 | MILK-1L | 2026-03-07 06:00:00 | -10 | 2026-03-07 06:00:11 |
| 19 | s3 | EGGS-6 | 2026-03-05 09:00:00 | 36 | 2026-03-05 09:00:16 |
| 20 | s3 | EGGS-6 | 2026-03-06 09:00:00 | -12 | 2026-03-06 09:00:08 |
| 21 | s1 | EGGS-6 | 2026-03-04 08:00:00 | 30 | 2026-03-04 08:00:19 |
| 22 | s1 | EGGS-6 | 2026-03-05 16:00:00 | -9 | 2026-03-05 16:00:06 |
22 rows — scroll inside the table to see them all.
Expected output
| store_id | sku | units_on_hand | late_events |
|---|---|---|---|
| s1 | BREAD | 30 | 1 |
| s1 | MILK-1L | 25 | 1 |
| s2 | EGGS-6 | 32 | 1 |
| s3 | MILK-1L | 60 | 1 |
4 rows — all rows shown.
Constraints
event_at at or before '2026-03-05 23:59:59', whenever it arrived.units_on_hand is the sum of delta_units over those events. Positive values are restocks, negative are picks.late_events counts the events in that window whose ingested_at is after the same cutoff — the rows the original report could not have seen.store_id, then sku.Worked example
Store s1 and MILK-1L: four events fall on or before the cutoff — +120, -40, -25 and a -30 pick at 18:40 on 5 March that did not arrive until 04:05 on 7 March. The true closing figure is 25 units with 1 late event.
The report sent that night filtered on ingested_at and reported 55 units. It was not wrong when it ran; it is wrong now. Filtering on ingested_at gives you what the warehouse knew, filtering on event_at gives you what happened — and only the second one is reproducible.
What this tests
The distinction between event time and processing time, and the restatement problem it creates: a correct report can become incorrect without anyone changing the query, so a pipeline has to be able to say which figures moved and why.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.