In a previous posting, we introduced nested types as one of the new features in StreamInsight V1.2. The second improvement in the type system represents the other end of the complexity spectrum, namely the ability to use "primitive" event types, without any struct or class. Remember the LINQ statement to compute the distances between two vehicles in that posting:

from b in vehicleB

select new

{

distance = Math.Sqrt(

Math.Pow(a.Loc.X – b.Loc.X, 2) +

Math.Pow(a.Loc.Y – b.Loc.Y, 2))

};

Wouldn’t it be nice to be able to write this as:

from b in vehicleB

select Math.Sqrt(

Math.Pow(a.Loc.X – b.Loc.X, 2) +

Math.Pow(a.Loc.Y – b.Loc.Y, 2));

Yes, it would – and in V1.2 you can! The type of this is now simply a CepStream<double>, and you can use it like this:

where d > 9

select d;

Beauty! But wait, there is more: in V1.2, we also enabled the LINQ Let clause. We can consolidate the above statements nicely into a single one:

from l in vehicleB

let d = Math.Sqrt(

Math.Pow(r.Loc.X - l.Loc.X, 2) +

Math.Pow(r.Loc.Y - l.Loc.Y, 2))

where d > 9

select d;

You can find this example attached to run in LINQPad.

See how we can create a very concise StreamInsight sample over a stream of int in LINQPad:

Application,

ev => PointEvent.CreateInsert(

DateTimeOffset.Now.AddMinutes(ev), ev),

AdvanceTimeSettings.StrictlyIncreasingStartTime);

var result = from win in source.TumblingWindow(TimeSpan.FromMinutes(5))

select win.Avg(e => e);

result.ToPointEnumerable().Where(e => e.EventKind == EventKind.Insert).Dump();

Alright, this query doesn’t really make a lot of sense, but you get the idea. This sample is also included in the set of new LINQPad samples – just update your LINQPad driver to get them.

Regards,

The StreamInsight Team