The GROUP BY part was fine, I got that out fast.
Use a GROUP BY on post_id to aggregate watch duration and screen coverage across all views. Apply a HAVING clause to filter groups where SUM(watch_duration) > X and MAX(screen_coverage) > Y. This single-pass aggregation is efficient and directly answers the question.
Pro tip: Mention that you would verify the grain of the table (one row per impression) and consider whether watch duration should be summed only for valid views (e.g., excluding bot traffic or very short views). Also, discuss indexing on post_id for performance if the table is large.
Identify the columns: post_id, watch_duration, screen_coverage, and possibly view_id or user_id. Confirm that each row represents a single impression/view event.
Group by post_id and compute SUM(watch_duration) as total_watch_duration and MAX(screen_coverage) as max_screen_coverage.
Use a HAVING clause to filter groups where total_watch_duration > X and max_screen_coverage > Y.
Return post_id (and optionally the aggregated metrics) for posts that meet both conditions.
Discuss handling NULLs, zero-duration views, and indexing strategies to optimize the query for large datasets.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Clarify the streaming framework and event schema, then design a stateful sessionization solution using a timer or watermark to detect 30-second inactivity. For each session, aggregate per-post watch time and max screen coverage, filter posts by effective-read criteria, and emit results when the session closes.
Pro tip: Emphasize that sessionization requires event-time processing with watermarks to handle out-of-order events and late data, and discuss how to scale state with keyed state and timers per user.
Confirm the streaming framework (e.g., Flink, Spark Structured Streaming), event schema (user_id, post_id, timestamp, watch_time, screen_coverage), and the exact effective-read criteria (e.g., watch_time >= 10s and screen_coverage >= 50%).
Key events by user_id, maintain session state with a timer set to 30 seconds after the last event. When the timer fires, close the session and emit its aggregated results.
Within each session, accumulate total watch time and max screen coverage per post. Use a dictionary or state object keyed by post_id.
When the session closes, filter posts that meet the effective-read criteria, and emit a record containing user_id, session_id, post_id, total_watch_time, and max_screen_coverage.
Use watermarks to allow for out-of-order events up to a bound, and discuss state management (e.g., RocksDB) and parallelism for scalability.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.