private static void ArrayBasedIngressExample() { // Create the first array segment. StreamEvent <Point>[] values1 = { StreamEvent.CreateInterval(1, 10, new Point { x = 1, y = 2 }), StreamEvent.CreateInterval(2, 10, new Point { x = 2, y = 4 }), StreamEvent.CreateInterval(3, 10, new Point { x = 3, y = 6 }), StreamEvent.CreateInterval(4, 10, new Point { x = 4, y = 8 }), StreamEvent.CreateInterval(5, 10, new Point { x = 5, y = 10 }) }; // Create the second array segment. StreamEvent <Point>[] values2 = { StreamEvent.CreateInterval(6, 10, new Point { x = 6, y = 12 }), StreamEvent.CreateInterval(7, 10, new Point { x = 7, y = 14 }), StreamEvent.CreateInterval(8, 10, new Point { x = 8, y = 16 }), StreamEvent.CreateInterval(9, 10, new Point { x = 9, y = 18 }), StreamEvent.CreatePunctuation <Point>(StreamEvent.InfinitySyncTime) }; var segment1 = new ArraySegment <StreamEvent <Point> >(values1); var segment2 = new ArraySegment <StreamEvent <Point> >(values2); var segments = new ArraySegment <StreamEvent <Point> >[] { segment1, segment2 }; // Array-based ingress. var input = segments.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void SelectFunc() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.WriteLine(); Console.WriteLine("Query: input.Select(r => new { Original = r, Squared = r * r, Text = \"Hello #\" + r })"); var output = input.Select(r => new { Original = r, Squared = r * r, Text = "Hello #" + r }); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void SelectManyFunc() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.WriteLine(); Console.WriteLine("Query: input.SelectMany(r => Enumerable.Repeat(r, 5))"); var output = input.SelectMany(r => Enumerable.Repeat(r, 5)); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void AlterLifetimeFunc() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.WriteLine(); Console.WriteLine("Query: input.AlterEventLifetime(oldStart => oldStart + 5, 2)"); var output = input.AlterEventLifetime(oldStart => oldStart + 5, 2); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void WhereFunc() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.WriteLine(); Console.WriteLine("Query: input.Where(r => r > 5)"); var output = input.Where(r => r > 5); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void WhereExample10() { StreamEvent <ValueTuple <int, int> >[] values2 = { StreamEvent.CreateInterval(1, 10, new ValueTuple <int, int> { Item1 = 1, Item2 = 2 }), StreamEvent.CreateInterval(2, 10, new ValueTuple <int, int> { Item1 = 2, Item2 = 4 }), StreamEvent.CreateInterval(3, 10, new ValueTuple <int, int> { Item1 = 3, Item2 = 6 }), StreamEvent.CreateInterval(4, 10, new ValueTuple <int, int> { Item1 = 4, Item2 = 8 }), StreamEvent.CreateInterval(5, 10, new ValueTuple <int, int> { Item1 = 5, Item2 = 10 }), StreamEvent.CreateInterval(6, 10, new ValueTuple <int, int> { Item1 = 6, Item2 = 12 }), StreamEvent.CreateInterval(7, 10, new ValueTuple <int, int> { Item1 = 7, Item2 = 14 }), StreamEvent.CreateInterval(8, 10, new ValueTuple <int, int> { Item1 = 8, Item2 = 16 }), StreamEvent.CreateInterval(9, 10, new ValueTuple <int, int> { Item1 = 9, Item2 = 18 }), StreamEvent.CreatePunctuation <ValueTuple <int, int> >(StreamEvent.InfinitySyncTime) }; var input = values2.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Apply a filter on one field. Console.WriteLine(); Console.WriteLine("Query: input.Where(p => p.x > 5)"); var output = input.Where(p => p.Item1 > 5); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void WhereExample1() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Apply a filter on one field. Console.WriteLine(); Console.WriteLine("Query: input.Where(p => p.x > 5)"); var output = input.Where(p => p.x > 5); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void SelectExample4() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.WriteLine(); Console.WriteLine("Query: input.Select(() => new Point3D(), p => p.z, p => p.x + p.y)"); // Map each Point object to a Point3D object by extracting existing fields and adding a new field z. var output = input.Select(() => new Point3D(), p => p.z, p => p.x + p.y); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void SelectExample2() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Map each Point object to an anonymous type object. Console.WriteLine(); Console.WriteLine("Query: input.Select(p => new { Distance = sqrt(p.x * p.x + p.y * p.y), Text = \"Point #\" + p.x })"); var output = input.Select(p => new { Distance = Math.Round(Math.Sqrt(p.x * p.x + p.y * p.y), 2), Text = "Point #" + p.x }); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void SelectManyExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Map each Point object to three Point objects. Console.WriteLine(); Console.WriteLine("Query: input.SelectMany(p => Enumerable.Repeat(p, 3))"); var output = input.SelectMany(p => Enumerable.Repeat(p, 3)); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void ArrayBasedEgressExample() { StreamEvent <Point>[] values = { StreamEvent.CreateInterval(1, 10, new Point { x = 1, y = 2 }), StreamEvent.CreateInterval(2, 10, new Point { x = 2, y = 4 }), StreamEvent.CreateInterval(3, 10, new Point { x = 3, y = 6 }), StreamEvent.CreateInterval(4, 10, new Point { x = 4, y = 8 }), StreamEvent.CreateInterval(5, 10, new Point { x = 5, y = 10 }), StreamEvent.CreateInterval(6, 10, new Point { x = 6, y = 12 }), StreamEvent.CreateInterval(7, 10, new Point { x = 7, y = 14 }), StreamEvent.CreateInterval(8, 10, new Point { x = 8, y = 16 }), StreamEvent.CreateInterval(9, 10, new Point { x = 9, y = 18 }), StreamEvent.CreatePunctuation <Point>(StreamEvent.InfinitySyncTime) }; var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Array-based egress. Console.WriteLine(); Console.WriteLine("Output ="); input.ToStreamEventArrayObservable().ForEachAsync( e => e.ToObservable().ForEachAsync(w => Console.WriteLine(w))).Wait(); Console.ReadLine(); }
private static void SelectExample3() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Map each Point object to a Point1D object (same as SelectExample1) by // automatically extracting fields defined in both types. Console.WriteLine(); Console.WriteLine("Query: input.Select(() => new Point1D())"); var output = input.Select(() => new Point1D()); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private QueryContainer CreateQuery() { var query = new QueryContainer(); Config.ForceRowBasedExecution = true; // incoming events are received via a conduit _tweetConduit = new Subject <StreamEvent <Tweet> >(); var streamInput = query.RegisterInput(_tweetConduit, OnCompletedPolicy.None(), DisorderPolicy.Drop(TimeSpan.FromSeconds(3).Ticks), PeriodicPunctuationPolicy.Time((ulong)TimeSpan.FromMilliseconds(1).Ticks)); // outgoing events are pushed to the dashboard var myOutput = query.RegisterOutput(TwitterAnalytics(streamInput), ReshapingPolicy.None()); myOutput.Subscribe(tweetEvent => Publish(tweetEvent)); return(query); }
private static void MaxExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Report the maximum value of payload values. Console.WriteLine(); Console.WriteLine("Query: input.Max(v => v)"); var output = input.Max(v => v); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void TopKExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Report the top 3 values of payload values. Console.WriteLine(); Console.WriteLine("Query: input.TopK(v => v, 3).SelectMany(v => v).Select(v => v.Payload)"); var output = input.TopK(v => v, 3).SelectMany(v => v).Select(v => v.Payload); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void ExtendLifetimeExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Extend all event lifetimes by 3. Console.WriteLine(); Console.WriteLine("Query: input.ExtendLifetime(3)"); var output = input.ExtendLifetime(3); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void UnaryClipExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Truncate all event lifetimes by a maximum lifetime length of 3. Console.WriteLine(); Console.WriteLine("Query: input.ClipEventDuration(3)"); var output = input.ClipEventDuration(3); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void SessionTimeoutExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Extend all event lifetimes as long as new events arrive within a period of 6. Console.WriteLine(); Console.WriteLine("Query: input.SessionTimeoutWindow(6)"); var output = input.SessionTimeoutWindow(6); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void PointAtEndExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Convert all interval events into point events at end. Console.WriteLine(); Console.WriteLine("Query: input.PointAtEnd()"); var output = input.PointAtEnd(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void CountExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Report the number of events. Console.WriteLine(); Console.WriteLine("Query: input.Count()"); var output = input.Count(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void MedianExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Report the median value of payload values. Console.WriteLine(); Console.WriteLine("Query: input.Aggregate(w => w.PercentileDiscrete(0.5, v => v))"); var output = input.Aggregate(w => w.PercentileDiscrete(0.5, v => v)); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void UDAExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Report the value of a user-defined aggregate function StandardDeviation. Console.WriteLine(); Console.WriteLine("Query: input.Aggregate(w => w.StandardDeviation(v => v), w => w.Count(), (std, count) => new { StandardDeviation= std, Count = count })"); var output = input.Aggregate(w => w.StandardDeviation(v => v), w => w.Count(), (std, count) => new { StandardDeviation = std, Count = count }); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void CompoundAggregateExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Report 3 aggregates in one query. Console.WriteLine(); Console.WriteLine("Query: input.Aggregate(w => w.Count(), w => w.Max(v => v), w => w.Average(v => v), (count, max, average) => new { Count = count, Max = max, Average = average })"); var output = input.Aggregate(w => w.Count(), w => w.Max(v => v), w => w.Average(v => v), (count, max, average) => new { Count = count, Max = max, Average = average }); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void SelectExample1() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Map each Point object to a Point1D object by extracting the field x. Console.WriteLine(); Console.WriteLine("Query: input.Select(p => new Point1D { x = p.x })"); var output = input.Select(p => new Point1D { x = p.x }); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void SelectExample5() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.WriteLine(); Console.WriteLine("Query: input.Select(() => new Point3D(), new Dictionary{{\"y\", p => p.y * 2 }, {\"z\", p => p.x + p.y }})"); // Map each Point object to a Point3D object by extracting the field x, updating the field y, and adding a new field z. var output = input.Select(() => new Point3D(), new Dictionary <string, Expression <Func <Point, object> > > { { "y", p => p.y * 2 }, { "z", p => p.x + p.y } }); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void CrossJoinExample() { var input1 = sessions1.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input1 ="); input1.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); var input2 = sessions2.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input2 ="); input2.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Corss join and generate anonymous type objects. Console.WriteLine(); Console.WriteLine("Query: input.Join(input2, (left, right) => new { ID1 = left.id, Type1 = left.type, ID2 = right.id, Type2 = right.type })"); var output = input1.Join(input2, (left, right) => new { ID1 = left.id, Type1 = left.type, ID2 = right.id, Type2 = right.type }); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void AntiJoinExample() { var input1 = sessions1.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input1 ="); input1.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); var input2 = sessions2.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input2 ="); input2.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Left anti join. Console.WriteLine(); Console.WriteLine("Query: input.WhereNotExists(input2, w => w.id, w => w.id)"); var output = input1.WhereNotExists(input2, w => w.id, w => w.id); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }
private static void GroupAggregateExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Every 5 time units, report the number of events and the sum of payload values for each group key. Console.WriteLine(); Console.WriteLine("Query: input.TumblingWindowLifetime(5).GroupAggregate(w => w / 3, w => w.Count(), w => w.Sum(v => v), (key, count, sum) => new { Key = key.Key, Count = count, Sum = sum })"); var output = input.TumblingWindowLifetime(5).GroupAggregate( w => w / 3, w => w.Count(), w => w.Sum(v => v), (key, count, sum) => new { Key = key.Key, Count = count, Sum = sum }); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void TumblingWindowCountExample() { var input = values.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input ="); input.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Every 3 time units, report the number of events that were being processed // at some point during that period. Report the result at a point in time, at the // end of the 3 time units window. var duration = 3; var offset = 0; Console.WriteLine(); Console.WriteLine("Query: input.TumblingWindowLifetime(3, 0).Count()"); var output = input.TumblingWindowLifetime(duration, offset).Count(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); Console.ReadLine(); }
private static void OuterJoinExample() { var input1 = sessions1.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input1 ="); input1.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); var input2 = sessions2.ToObservable().ToStreamable(OnCompletedPolicy.None()); Console.WriteLine("Input2 ="); input2.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); // Left outer join. Console.WriteLine(); Console.WriteLine("Query: input.LeftOuterJoin(input1, w => w.id, w => w.id, w => new { ID = w.id, Type1 = w.type, Type2 = 0 }, (left, right) => new { ID = left.id, Type1 = left.type, Type2 = right.type })"); var output = input2.LeftOuterJoin(input1, w => w.id, w => w.id, w => new { ID = w.id, Type1 = w.type, Type2 = 0 }, (left, right) => new { ID = left.id, Type1 = left.type, Type2 = right.type }); Console.WriteLine(); Console.WriteLine("Output ="); output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait(); }