Partitioned Windows
Windows that tracks statistics separately for individual keys.
For example, assuming you have a stream message that contains a stock SYMBOL and a stock BID. Suppose you want a window to calculate separate BID aggregations for each individual stock SYMBOL, such as the average price of TSLA, the average price of APPL, the average price of GOOG, and so on. Instead of manually defining a window for each stock symbol, you can define a window once that is partitioned by the stock SYMBOL field as the key. With this, you instantiate the window only once, and let RioDB track the BID stats of each SYMBOL separately.
Optionally, you may want to drop a partition (or a particular key) from your window if it hasn’t posted any messages with that key in a while. An example would be if you are tracking stats for user sessions on a server, and after a user has not shown any activity, maybe you want to drop that user session stats to save RAM.
Access Rule
Requires WINDOW, STREAM or ADMIN role.
Syntax
PARTITION BY <symbol>
The EXPIRE clause is optional and must be a positive integer followed by one character, which may be s seconds, m minutes, h hours, d days.
PARTITION BY <symbol>
EXPIRATION <time integer><time unit>
Example
CREATE WINDOW last_1000_bids_by_symbol
RUNNING min, max, avg, slope
FROM my_stock_stream.bid
PARTITION BY symbol
RANGE 1000;
CREATE WINDOW last_1000_bids_by_symbol_exp
RUNNING min, max, avg, slope
FROM my_stock_stream.bid
PARTITION BY symbol
EXPIRE 10m
RANGE 1000;
Important Considerations:
- Each window partition is not full until enough values have been received or enough time has passed. It’s possible to have some partitions that are full while others are only partially full or completely empty. Queries are executed for each partition. If only full partitions are relevant to you, then make sure you use the “window.IS_FULL” condition in your queries.
- Consider the RAM available if expecting A LOT of different keys. 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 actual scenario.