Print

Fixed-Size Window

Windows with a fixed quantity of elements. These work like a “first in, first out” queue. Let’s say you have a window of fixed-size of 100 elements. Each time a new element is inserted into the first slot, the oldest element in the 100th slot (if the window is full) is evicted, thereby maintaining a fixed size of 100 elements.

The range can optionally begin after a desired offset. For example, let’s say that from the 100 most recent messages, you want the window range to span from the 21st most recent message to the 100th most recent message. This means that the 20 most recent messages do not enter the window, yet, but wait until they become the 21st most recent. This is achieved using the OFFSET clause, which is optional.

Access Rule

Requires WINDOW, STREAM or ADMIN role.

Syntax

RANGE <positive integer representing the window size> 

Window with the OFFSET option:

RANGE <positive integer representing the window size>
OFFSET <positive integer representing the offset size> 

Example

A window containing 1000 most recent elements:

CREATE WINDOW last_1000_bids
RUNNING min, max, avg, slope
FROM my_stock_stream.bid
RANGE 1000;

A window spanning from the 20th most recent to the 100th most recent element:

CREATE WINDOW last_20_to_100_bids
RUNNING min, max, avg, slope
FROM my_stock_stream.bid
RANGE 80
OFFSET 20;

Important Considerations:
The window is not full until RioDB receives enough messages from the stream to fill the window. Queries are executed on ALL windows, full or not. If only full windows are relevant to you, then add the condition “WHEN my_window.IS_FULL” to your queries.

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

Table of Contents
Scroll to Top