Stream Policy

The stream policy (also known as a window policy) is used for continuous queries only. It determines what kind of window is used: a time window, sliding window, or tumbling window.

See Working With Sliding Tumbling and Time Windows and examples following: Sliding Window Examples (Cache Queries), Tumbling Window Examples (Cache Queries), and Time Window Examples (Cache Queries).

Note that continuous queries that use an implicit window do not have a stream policy. See Working With Implicit Windows.

The value of long literal specifies the size of the window. When used for a time window, the value refers to a time unit specified by time unit. The time unit can be specified in milliseconds, seconds, minutes, hours or days. For example: maintain last 5 minutes defines a time window of five minutes.

For sliding and tumbling windows, the number refers to a number of entities.

Using Clause

When the query specifies time units, you can specify a start time by including a using clause. The expression could refer to a timestamp property in the entity, for example. If the using clause is absent, the start time is the moment the entity enters the window.

Where Clause

The optional where clause is used as a pre-filter (a filter on results that enter the window). It eliminates entities that are not useful for the query, optimizing performance.

By Clause

Maintaining a single window (like a sliding window) over all the events in the window may not be what you need for a query. The (optional) by clause allows you to do aggregations within the window. In this regard, the by clause is similar to the group by clause.

For example, instead of a single window of size 50 that contains all the entities, you can maintain a window of size 50 for each combination of values for the fields in the by section:

select car.id, car.color from "CarEvent" {policy: maintain last 50 sliding  where type = "Sedan" by country, state, city} car;

See Explicit Window Example (Cache Query) for a detailed discussion of an example that uses a stream policy. See Time Window Examples (Cache Queries) for more examples.