Sessionize Search Logs and Find Sessions That End Without a Click

Last updated: November 29, 2026

Quick Overview

From a log of search and click events, group events into sessions split by 30 minutes of inactivity, then report per day the fraction of sessions that contained a search but no result click.

Google
Data Manipulation (SQL/Python)
Data Scientist
Google
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


From a log of search and click events, group events into sessions split by 30 minutes of inactivity, then report per day the fraction of sessions that contained a search but no result click.

Abandonment rate is a core Search quality metric, and computing it requires sessionization, a classic window-function exercise. Interviewers check gap logic, cumulative sums for session ids, tie handling, and the metric definition.

What the Interviewer Expects
  • Use LAG to compute gaps between consecutive events per user
  • Flag session starts and cumulative-sum them into session ids
  • Aggregate per session with conditional counts
  • Compute the daily rate with a clear denominator
  • Handle ties and sessions spanning midnight
Key Topics to Cover
Sessionization
Window functions
LAG
Cumulative sum
Abandonment rate
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • Should a session with an answer box but no click count as abandoned?
  • How would you change the gap threshold and test its sensitivity?
  • How would you do this in a streaming pipeline?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

search_events(event_id STRING, user_id STRING, event_ts TIMESTAMP, event_type STRING) with event_type in ('search', 'click'). A new session starts when the gap since the user's previous event is 3...

Approach
  1. LAG gives each event's previous timestamp per user.
  2. Mark is_new = 1 when there is no previous event or the gap is at least 30 minutes.
  3. Running sum of is_new per user gives a session num...

Submit Your Answer
Markdown supported