Using rstream
Normally, in stream queries, you select items that are currently in the stream or window. Adding the keyword rstream to a select clause causes it to select the items that are currently leaving the stream or window. The main use of this is to delay events, either by a time period or by a number of events. The delayed event is typically compared to the set of events that arrived after it, up until the current time, as illustrated by the code example below.
01. stream<float> tNow := from t in all Temperature(sensorId="T001")
02. select t.temperature;
03. stream<float> tDelayed := from t in tNow retain 10 select rstream t;
04. float t; 05. from t1 in tDelayed from t2 in tNow retain 10 where t2 > t1 * 1.
05 select t2 : t
06. print "Rapid temperature rise: " + t.toString();
07. }