Application Development CHAPTER 8 157
As you might guess, the key to working with windows is to have a clear understanding of
the time span that each window covers. There are three types of window streams that Stream-
Insight supports—hopping windows, snapshot windows, and count windows. In a hopping
windows stream, each window spans an equal time period. In a snapshot windows stream,
the size of a window depends on the events that it contains. By contrast, the size of a count
windows stream is not xed, but varies according to a specied number of consecutive event
start times.
To create a hopping window, you specify both the time span that the window covers (also
known as window size) and the time span between the start of one window and the start of
the next window (also known as hop size). For example, assume that you need to create win-
dows that cover a period of one hour, and a new window starts every 15 minutes, as shown in
Figure 8-3. In this case, the window size is one hour and the hop size is 15 minutes. Here is the
code to create a hopping windows stream and count the events in each window:
var outputStream = from eventWindow in
inputStream.HoppingWindow(TimeSpan.FromHours(1), TimeSpan.FromMinutes(15))
select new { count = eventWindow.Count() };
0
30
60 90 120
e1
e2
e1
e2
e2
e3
e3
Input
events
Time (minutes)
e1
e2
e3
Hopping
windows
FIGURE 8-3 Hopping windows
When there are no gaps and there is no overlap between the windows in the stream,
hopping windows are also called tumbling windows. Figure 8-2, shown earlier, provides an
example of tumbling windows. The window size and hop size are the same in a tumbling
Comments to this Manuals