Chapter 8 Working With Continuous Queries : Working With Implicit Windows

Working With Implicit Windows
Implicit windows are created when the query does not have an explicit policy (window) clause, and the query is executed as a continuous query (see Executing a Continuous Query).
The lifecycle of an entity within an implicit window is affected by the life cycle of that entity in the cache:
Deletion of entities may cause an update of the query output, depending on the query text.
Example
select count(*) from /EventA evt group by 1;
The example shows a group by 1 clause. This is a dummy group, required because aggregate functions, count(*) in this case, require a group by clause.
Suppose that for the first 10 minutes after the query statement is executed, 100 events are created in quick succession. Every time the query receives a new event notification, the count goes up progressively until it stabilizes at 100.
Suppose that thirty minutes later, 50 of those 100 events are consumed by a rule or expire because of their time to live (TTL) settings. The events are deleted from the cache. The query receives deletion notifications and the query output, count(*), changes until it drops and stabilizes at 50.
Implicit Window Examples

 
select d.name, count(*), avg(s.age)
  from /Department d, /Student s
  where d.name = s.deptName
  group by d.name;

 
The above query joins Department and Student entities using the department name. It then keeps a count and an average of age of students per department.

 
select s.deptName, count(*)
  from /Student s
  group by s.deptName
  order by count(*);

 
The above query keeps count of the number of students per department. Every time a student enrolls or leaves, the count changes and the query produces the entire list sorted on the count.