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.
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
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- 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 ProblemsSample 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
LAGgives each event's previous timestamp per user.- Mark
is_new = 1when there is no previous event or the gap is at least 30 minutes. - Running sum of
is_newper user gives a session num...