Application Development CHAPTER 8 161
Joins
You can use a join operation to match events from two streams. The CEP server rst matches
events only if they have overlapping time intervals, and then applies the conditions that you
specify in the join predicate. The output of a join operation is a new event that combines pay-
loads from the two matched events. Here is the code to join events from two input streams,
where eld x is the same value in each event. This code creates a new event containing elds
x and y from the rst event and eld y from the second event.
var outputStream = from e1 in inputStream1
join e2 in inputStream2
on e1.x equals e2.x
select new { e1.x, e1.y, e2.y };
Another option is to use a cross join, which combines all events in the rst input stream
with all events in the second input stream. You specify a cross join by using a from clause for
each input stream and then creating a new event that includes elds from the events in each
stream. By adding a where clause, you can lter the events in each stream before the CEP
server performs the cross join. The following example selects events with a value for eld x
greater than 5 from the rst stream and selects events with a value for eld y less than 20
from the second stream, performs the cross join, and then creates a stream of new events
containing eld x from the rst event and eld y from the second event:
var outputStream = from e1 in inputStream1
from e2 in inputStream2
where e1.x > 5 && e2.y < 20
select new { e1.x, e2.y };
Unions
You can also combine events from multiple streams by performing a union operation. You
can work with only two streams at a time, but you can cascade a series of union operations if
you need to combine events from three or more streams, as shown in the following code:
var outputStreamTemp = inputStream1.Union(inputStream2);
var outputStream = outputStreamTemp.Union(inputStream3);
User-dened Functions
When you need to perform an operation that the CEP server does not natively support, you
can create user-dened functions (UDFs) by reusing existing .NET functions. You add a UDF to
the CEP server in the same way that you add an adapter. You can then call the UDF anywhere
in your query where an expression can be used, such as in a lter predicate, a join predicate,
or a projection.
Comments to this Manuals