Last active
August 29, 2015 14:07
-
-
Save yalisassoon/735a9710b878556ea7a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- For every event, identify the previous event timestamp and session index | |
SELECT | |
dvce_tstamp AS current_tstamp, | |
LAG(dvce_tstamp, 1) | |
OVER (PARTITION BY domain_userid ORDER BY dvce_tstamp) AS previous_tstamp, | |
domain_sessionidx AS current_session_index, | |
LAG(domain_sessionidx, 1) | |
OVER (PARTITION BY domain_userid ORDER BY dvce_tstamp) AS previous_session_index | |
FROM atomic.events; | |
-- We can query that data to identify if there are any cases where the session_index has failed | |
-- to increment after a user has been inactive for more than 30 minutes | |
SELECT | |
* | |
FROM ( | |
SELECT | |
dvce_tstamp AS current_tstamp, | |
LAG(dvce_tstamp, 1) | |
OVER (PARTITION BY domain_userid ORDER BY dvce_tstamp) AS previous_tstamp, | |
domain_sessionidx AS current_session_index, | |
LAG(domain_sessionidx, 1) | |
OVER (PARTITION BY domain_userid ORDER BY dvce_tstamp) AS previous_session_index | |
FROM atomic.events | |
) t | |
WHERE current_session_index = previous_session_index | |
AND EXTRACT(MIN FROM (current_tstamp - previous_tstamp)) > 30; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment