StreamInsight - sample LINQ

Discussion created by gmoffett Employee on Aug 25, 2010
Latest reply on Aug 26, 2010 by hanyong


You may have heard of or used Microsoft StreamInsight, PI for Streaminsight or LINQ. The following post includes a snippet of LINQ when used with Microsoft StreamInsight and PI for StreamInsight. Idea is to give a taste of what a query would look like.


Microsoft StreamInsight makes use of Language Integrated Queries (LINQ) and processes data as streams in user defined time slices. Think of a river flowing by and you are looking at time periods (windows) associated with what flows past (events)


For example if your time window (you can have multiple different length time windows) is 5 minutes, you collect all the events for that 5 minute window and then you can perform queries on those events (calculations and perform output) then repeat the process.


So in the case of the river example after the 5 minute window you may want to count the number of events , where events could include fish or boats that went by.

The following code snippet is an example of LINQ in a C# .NET program that is creating a PI event (tag name and value) with the count of events for the time window.

varcountStream = from window ininputDataStream.TumblingWindow(Period, DateTime.Today, HoppingWindowOutputPolicy.ClipToWindowEnd)
select new PIEventBasic<double>
                          Path = summaryTag,
                          Value = window.Count(),
                          Status = 0,
                          Id = 0


CountStream is the output stream from the query which in this example will contain one PI Event. This stream could then be written to PI using the PI Archive Adapter (for another post or example!) or joined with another stream or used in another query.


InputDataStream is the input from the PI Input Adapter (or other adapter(s)) and defines the window of time we are processing


The select creates a new PI event, where path is the tagname and value is populated with the count of events from the window of the InputStream


If you would like more information about StreamInsight there is a webinar available from earlier this year which provides an overview and a CTP available in the vCampus download center > pre-release category if you would like to explore using PI for StreamInsight with Microsoft StreamInsight.