SESSION_COUNT

Gets the number of sessions, where a session is defined as events separated by no more than WINDOWSIZE time.

Syntax

SESSION_COUNT(TIME[, WINDOWSIZE(WHERE cond)])

Arguments

TIME: An expression of any type that can be ordered. WINDOWSIZE: An optional boolean expression filtering the rows used for aggregation. STORED SESSIONS: This is optional. If it is omitted there is, in effect, no limit.

Returns

The result type matches the type of the argument.

Notes

Nulls are not counted. In Athena, SESSION_COUNT data can be BIGINT or NUMBER type. In Upsolver output, SESSION_COUNT data can be NUMBER type only.

Example

Data

[
   {
      "serverIp":"10.0.0.1",
      "time":1628894700000,
      "cpuUsage":52.3
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628894760000,
      "cpuUsage":2.4
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628894820000,
      "cpuUsage":99.3
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628894880000,
      "cpuUsage":99.6
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628894940000,
      "cpuUsage":12.3
   },
   {
      "serverIp":"10.0.0.1",
      "time":1628895000000,
      "cpuUsage":55
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894700000,
      "cpuUsage":2.3
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894760000
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894820000,
      "cpuUsage":9.3
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894880000,
      "cpuUsage":9.6
   },
   {
      "serverIp":"10.0.0.2",
      "time":1628894940000,
      "cpuUsage":2.3
   }
]

Query

Find the number of sessions on each serverIp:

SET
   DATE_TIME = UNIX_EPOCH_TO_DATE(data.time);
SET
   string_date = TO_STRING(data.time);
SELECT
   data.serverIp AS serverip:STRING,
   SESSION_COUNT(data.time, data.cpuUsage) 
        AS session_count_data_cpuusage__60000:NUMBER
FROM
   "TIME_SERIES_DATA_w_NULL" 
GROUP BY
   data.serverIp

Results

{
   "session_count_data_cpuusage60000":4,
   "serverip":"10.0.0.2"
}{
   "session_count_data_cpuusage60000":6,
   "serverip":"10.0.0.1"
}

COUNT

Dialog

Last updated