Specifications
Application Development CHAPTER 8 155
Queries
After you create an event stream object, you write a LINQ expression on top of the event
stream object. You use LINQ expressions to dene the elds for output events, to lter events
before query processing, to group events into subsets, and to perform calculations, aggre-
gations, and ranking. You can even use LINQ expressions to combine events from multiple
streams through join or union operations. Think of LINQ expressions as the questions you ask
of the streaming data.
Projection
The projection operation, which occurs in the select clause of the LINQ expression, allows you
to add more elds to the payload or apply calculations to the input event elds. You then
project the results into a new event by using eld assignments. You can create a new event
type implicitly in the expressions, or you can refer to an existing event type explicitly.
Consider an example in which you need to increment the elds x and y from every event in
the inputStream stream by one. The following code example shows how to use eld assign-
ments to implicitly dene a new event type by using projection:
var outputStream = from e in inputStream
select new {x = e.x + 1, y = e.y + 1};
To refer to an existing event type, you cannot use the type’s constructor; you must use
eld assignments in an expression. For example, assume you have an existing event type
called myEventType. You can change the previous code example as shown here to reference
the event type explicitly:
var outputStream = from e in inputStream
select new myEventType {x = e.x + 1, y = e.y + 1};
Filtering
You use a ltering operation on a stream when you want to apply operations to a subset of
events and discard all other events. All events for which the expression in the where clause
evaluates as true pass to the output stream. In the following example, the query selects
events where the value in eld x equals 5:
var outputStream = from e in inputStream
where e.x == 5
select e;