Skip to main content

Bounding data with windows

When a CQ's source is a stream, it is limited to acting on single events, as in this example from MultiLogApp:

CREATE CQ GetErrors 
INSERT INTO ErrorStream 
SELECT log4j 
FROM Log4ErrorWarningStream log4j WHERE log4j.level = 'ERROR';

This triggers an alert whenever an error appears in the log.

To aggregate, join, or perform calculations on the data, you must create a bounded data set. The usual way to do this is with a window, which bounds the stream by a specified number of events or period of time. As discussed in the Concepts Guide (see Window), this may be a sliding window, which always contains the most recent set of events, or a jumping window, which breaks the stream up into successive chunks.

The basic programming pattern for a window is:

stream > window > CQ

What properties a window should have depend on the nature of the data in the input stream and what you want the CQ to do with it. There are six basic variations depending on whether you are bounding the data batches (jumping) or continuously (sliding) and whether you are bounding by by time, event count, or both.