Combining time-based and size-based windows
Sometimes you might want to focus on the last n items received in the last d seconds. To define a window that retains items based on both time and size, use the following format in the from clause:
within windowDurationExpr retain windowSizeExpr
The within keyword and expression must be first and the retain keyword and expression must be second. As with separate size-based and time-based windows, replace windowDurationExpr with an expression that returns a number of seconds, d, as a float value. Replace windowSizeExpr with an expression that indicates how many items you want to retain in the window, n, as an integer value. The window contains the last n items received in the last d seconds. If no items were received in the last d seconds, the window is empty. For example:
from v in values within 2.5 retain 2 select sum(v);
The following diagram, which uses the same notation as the previous section, illustrates how this works in practice.
The query before the diagram corresponds to the aggregate projection. The three queries shown here are:
Simple istream Projection | from v in values within 2.5 retain 2 select v |
Simple rstream Projection | from v in values within 2.5 retain 2 select rstream v |
Aggregate Projection | from v in values within 2.5 retain 2 select sum(v); |
The important point to note in this example is that some items drop out of the window before the 2.5 second period is passed. When e2 arrives, e0 and e1 are already in the window. Even though e0 has been there for only 2 seconds, it is removed because e1 and e2 are now the two most recent items received in the last 2.5 seconds.
Copyright © 2013
Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.