Specifications
158 CHAPTER 8 Complex Event Processing with StreamInsight
windows stream. Although you can use the HoppingWindow method to create tumbling win-
dows, there is a TumblingWindow method. The following code illustrates how to count events
in tumbling windows that occur every half hour.
var outputStream = from eventWindow in
inputStream.TumblingWindow(TimeSpan.FromMinutes(30))
select new { count = eventWindow.Count() };
Snapshot windows are similar to tumbling windows in that the windows do not overlap,
but whereas xed points in time determine the boundaries of a tumbling window, events
dene the boundaries of a snapshot window. Consider the example in Figure 8-4. At the start
of the rst event, a new snapshot window starts. That window ends when the second event
starts, and a second snapshot window starts and includes both the rst and second event.
When the rst event ends, the second snapshot also ends, and a third snapshot window
starts. Thus, the start and stop of an event triggers the start and stop of a window. Because
events determine the size of the window, the Snapshot method takes arguments, as shown in
the following code, which counts events in each window:
var outputStream = from eventWindow in inputStream.Snapshot()
select new { count = eventWindow.Count() };
e1
e2
e1
e1
e2
e2
e3
Input
events
Time
e3
Snapshot
windows
FIGURE 8-4 Snapshot windows