Question 360
A silver data engineer receives multiple updates for each entity and wants deterministic results. The team implements Use `LAG()` partitioned by device and ordered by event time. The goal was: An engineer wants to identify the immediately preceding event for each device. Which observed result best verifies success?
Explanation
Correct Answer
The team used Use `LAG()` partitioned by device and ordered by event time to fulfill “An engineer wants to identify the immediately preceding event for each device.” Observing The previous-event field matches the correct prior event per device confirms the intended effect in the resulting workload.
Incorrect Answers
The winning row is deterministic even for same-timestamp updates pertains to a different control (Use `ROW_NUMBER()` partitioned by order ID with descending event time and tie-breaker) and a different need (Only the most recent event per order ID should remain by business event time and sequence). It cannot establish that Use `LAG()` partitioned by device and ordered by event time met the stated goal.
This signal belongs to the adjacent case “The application needs a cumulative revenue amount over each customer's ordered transactions,” whose remedy is Use a window `SUM()` ordered by transaction time with an explicit frame. The observed result for the present requirement is The previous-event field matches the correct prior event per device.
Repeated executions select the same intended winner would demonstrate the separate action Add a stable event sequence or ingestion tie-breaker to the window ordering, which addresses “Two rows have the same timestamp and arbitrary selection would cause inconsistent history.” It does not verify the requirement “An engineer wants to identify the immediately preceding event for each device” following Use `LAG()` partitioned by device and ordered by event time.