public static StreamCache <Empty, T> Sort <T, U>(this IStreamable <Empty, T> stream, Expression <Func <T, U> > sortBySelector) { var u_comparer = Utility.CreateCompoundComparer(sortBySelector, ComparerExpression <U> .Default.GetCompareExpr()).Compile(); IStreamable <Empty, T> stream2 = stream; stream.GetProperties(out StreamProperties <Empty, T> properties); if (!properties.IsStartEdgeOnly) { var secondStream = new StreamEvent <T>[] { StreamEvent.CreateStart(StreamEvent.MaxSyncTime, default(T)), StreamEvent.CreatePunctuation <T>(StreamEvent.InfinitySyncTime), }.ToObservable().ToStreamable(); stream2 = stream.Join(secondStream, (x, y) => x); } var observableCache = stream2.ToPayloadEnumerable().ToList(); observableCache.Sort(new Comparison <T>(u_comparer)); var str = observableCache.ToObservable() .ToAtemporalStreamable(TimelinePolicy.Sequence(80000)) ; var str2 = str .SetProperty().IsConstantDuration(true, StreamEvent.InfinitySyncTime) ; var str3 = str2.Cache(); return(str3); }
private static void JoinPointsTest(bool fixedInterval = false) { var left = new Subject <StreamEvent <string> >(); var right = new Subject <StreamEvent <string> >(); var qc = new QueryContainer(); IStreamable <Empty, string> leftInput = qc.RegisterInput(left); IStreamable <Empty, string> rightInput = qc.RegisterInput(right); if (fixedInterval) { leftInput = leftInput.AlterEventDuration(1); rightInput = rightInput.AlterEventDuration(1); } var query = leftInput.Join( rightInput, l => (l != null ? l[0].ToString() : null), r => (r != null ? r[0].ToString() : null), (l, r) => $"{l},{r}"); var output = new List <StreamEvent <string> >(); qc.RegisterOutput(query).ForEachAsync(o => output.Add(o)); var process = qc.Restore(); // Should match and egress immediately left.OnNext(StreamEvent.CreatePoint(100, "A1")); right.OnNext(StreamEvent.CreatePoint(100, "A2")); process.Flush(); var expected = new StreamEvent <string>[] { StreamEvent.CreatePoint(100, "A1,A2"), }; Assert.IsTrue(expected.SequenceEqual(output)); output.Clear(); left.OnCompleted(); right.OnCompleted(); }