Print

Time-Based Window

Windows with elements that match a certain time range.
For example:

  • All messages received during the past 5 minutes.
  • All messages received during between 10 minutes ago and 5 minutes ago.

The timestamp used for this will depend on whether the STREAM definition in RioDB has a field assigned as the message timestamp or not. If there is one, then the timestamp field will be used to determine when message values enter and leave the window. If the stream definition does NOT have a field assigned as timestamp, then RioDB will rely on the system clock, and message values will be inserted into and evicted from the window based on the system clock.

Note, using a timestamp value from the stream message is almost always more precise. Using the system clock will not compensate for network transmission delays, and messages may be off by a few milliseconds.

Access Rule

Requires WINDOW, STREAM or ADMIN role.

Syntax

The range number followed by s, m, h, or d will set the window as a window of time. RANGE 30s means a window of 30 seconds. 30m means 30 minutes. 30h means 30 hours. And 30d means 30 days. That will be the time span of the window.

RANGE <positive integer><character representing time unit> 
RANGE <positive integer><time unit>-<positive integer><time unit> 

Example

CREATE WINDOW last_1000_bids
RUNNING min, max, avg, slope
FROM my_stock_stream.bid
RANGE 5m;
CREATE WINDOW last_1000_bids
RUNNING min, max, avg, slope
FROM my_stock_stream.bid
RANGE 100s-20s;

Important considerations:

  1. The window is not full until enough time has passed to cover the range since window creation. For example, if you create a window with range of 5 minutes, it will take 5 minutes for the window to be considered full. Queries are executed on ALL existing windows, even before enough time has passed to consider the window full. If only full windows are relevant to you, then make sure you use the “window.IS_FULL” condition in your queries.
  2. Consider the RAM available if expecting windows containing A LOT of data. Every use-case is different, so the best guideline here is to monitor RAM consumption using a sample test, and use it as a basis to estimate your FULL window scenario.

Note, Fixed-Size windows usually outperform Time-Based windows both in throughput and saving memory.

Table of Contents
Scroll to Top