Upsolver
Search…
DYNAMIC_SESSIONS
Collects an array of start and end times of sessions. A session is defined as a group of events that are not separated by a gap of more than the configured WINDOWSIZE.

Syntax

DYNAMIC_SESSIONS([MAX SESSIONS, ]TIME, WINDOWSIZE)

Arguments

MAX SESSIONS: The maximum number of entries that can be counted (default: 2,147,483,647). When MAX SESSIONS is omitted, the limit is simply set to the default value. TIME: The time value associated with this event. This is the value that is used to calculate the gap. WINDOWSIZE: The window gap size to use. This value should be in the same time unit as TIME. ‌

Returns

An integer

Example

Data

1
[
2
{
3
"userId":1,
4
"time":1628894700000,
5
"level":1,
6
"event":"passed"
7
},
8
{
9
"userId":1,
10
"time":1628894760000,
11
"level":2,
12
"event":"passed"
13
},
14
{
15
"userId":1,
16
"time":1628894820000,
17
"level":3,
18
"event":"lost"
19
},
20
{
21
"userId":1,
22
"time":1628895000000,
23
"level":3,
24
"event":"passed"
25
},
26
{
27
"userId":1,
28
"time":1628895060000,
29
"level":4,
30
"event":"passed"
31
}
32
]
Copied!

Query:

After collecting data about users who reach a mobile game level, you may want to get some information about their gaming sessions:
1
SELECT
2
data.userId AS userid:BIGINT,
3
DYNAMIC_SESSIONS(data.time, 60000) AS dynamic_sessions_data_time__60
4
FROM
5
"SESSION_DATA"
6
GROUP BY
7
Copied!

Results:

1
{
2
"userid":1,
3
"dynamic_sessions_data_time__60":[
4
{
5
"endTime":1628894820000,
6
"startTime":1628894700000
7
},
8
{
9
"endTime":1628895060000,
10
"startTime":1628895000000
11
}
12
]
13
}
Copied!

Dialog

Last modified 8mo ago