Link: http://blogs.msdn.com/ B /streaminsight/archive/2010/11/23/windows-part-1-the-basics.aspx
Original Author: Roman schindlauer-Senior Program Manager of streaminsight, whose boss is Torsten grabs mentioned in the previous blog.
If you begin to learn how to write streaminsight queries, the first concept most likely to come across is windows ). In this blog post, we will introduce how to use the window, hoping to help readers better understand some of the advantages and restrictions of using the window. Haha, the window here is not Microsoft Windows.
In the event processing world, a window is used to define a set, and these sets will become the objects of some set operations. These operations may be:
- Aggregate operations for calculating a single result, such as sum, Count, Min, Max, or custom aggregate operations;
- Return multiple form-based operation results, such as the topk or user-defined operators.
The streaminsight window splits the timeline into fragments.
The length of the streaminsight window can be a fixed time span (HOP window hoppingwindow and tumblingwindow), or it can be determined by the event itself (count window countingwindow and snapshot window snapshotwindow ). Is an example of a "window", where "sum" is used in some load domains:
Window and set operations often need to be put together for operations. A Window integrating set operations can be seen as a "Building Block" in streaminsight queries ". The following describes how to construct a query with a set operation and a window using LINQ:
var result = from window in input .TumblingWindow(TimeSpan.FromMinutes(5), HoppingWindowOutputPolicy.ClipToWindowEnd) select new { sum = window.Sum(e => e.Value) };
The components that combine window and set operations above this class accept cepstream and generate cepstream. First, the window Extension function returns cepwindowstream, and then applies the set operation on it. Next we will write another blog post to discuss these specific window types.
Sometimes, when you think of a window as just "a collection of events in the memory", you will be asked about how to "access" the window in different ways. Indeed, a window is a collection of events in streaminsight's controllable memory and can be accessed programmatically: User-defined aggregate operations (Udas) or user-defined operators (udos ). These extended interfaces allow you to write C # code to operate events in the window, such as generating a single aggregation result (using UDA) or generate one or more complete events (using UDO ). These are provided as subtypes in the streaminsight API. The best thing about these interfaces is that although they introduce imperative programming in the streaminsight event processing stream, they also support declarative models: accept event sets (Windows) and outputs some results accordingly. In this process, you do not need to worry about the order in which UDA or Udo will be called at runtime. In addition, because the input event set in this interface is ienumerable, we can also compile the LINQ to objects on it!
This may sound tempting for developers who have not yet played an advanced Declarative Programming Model (for example, writing UDA/Udo with LINQ, however, we recommend that you first use the built-in streaminsight operator to write some queries to familiarize yourself with the runtime of streaminsight.
In this case,
Roman