microsoft / Trill

Trill is a single-node query processor for temporal or streaming data.
MIT License
1.25k stars 133 forks source link

Jonathan keaveney #125

Closed JonathanKeav closed 4 years ago

JonathanKeav commented 4 years ago

Hi

If I run the following code

` SensorReading[] historicData = new[] { new SensorReading { Time = 1, Value = (decimal)0.33 }, new SensorReading { Time = 2, Value = 20 }, new SensorReading { Time = 3, Value = 15 }, new SensorReading { Time = 4, Value = 30 }, new SensorReading { Time = 5, Value = 45 }, // Here we crossed the threshold upward new SensorReading { Time = 6, Value = 50 }, new SensorReading { Time = 7, Value = 30 }, // Here we crossed downward. Note that the current query logic only detects upward swings. new SensorReading { Time = 8, Value = 35 }, new SensorReading { Time = 9, Value = 60 }, // Here we crossed upward again new SensorReading { Time = 10, Value = 20 } }; var streamable1 = historicData .ToObservable().ToTemporalStreamable(r => r.Time, r => r.Time + 10);

var output = streamable1.TumblingWindowLifetime(3) .Aggregate( w => w.Max(x => x.Value), w => w.Min(v => v.Value), (max, min) => new { Max = max, Min = min }); I get this error System.InvalidCastException HResult=0x80004002 Message=Unable to cast object of type 'Microsoft.StreamProcessing.PrimitiveComparerExpression1[System.UInt64]' to type 'Microsoft.StreamProcessing.IComparerExpression1[System.Decimal]'. Source=Microsoft.StreamProcessing StackTrace: at Microsoft.StreamProcessing.ComparerExpressionCache.TryGetCachedComparer[T](IComparerExpression1& comparer) in C:\Users\jonathan.keaveney\githubrepo\Trill\Sources\Core\Microsoft.StreamProcessing\Utilities\ComparerExpression.cs:line 56 at Microsoft.StreamProcessing.ComparerExpression1.get_Default() in C:\Users\jonathan.keaveney\githubrepo\Trill\Sources\Core\Microsoft.StreamProcessing\Utilities\ComparerExpression.cs:line 80 at Microsoft.StreamProcessing.Aggregates.TumblingMaxAggregate1..ctor() in C:\Users\jonathan.keaveney\githubrepo\Trill\Sources\Core\Microsoft.StreamProcessing\Aggregates\TumblingMaxAggregate.cs:line 18 at Microsoft.StreamProcessing.Window2.Max[TValue](Expression1 selector) in C:\Users\jonathan.keaveney\githubrepo\Trill\Sources\Core\Microsoft.StreamProcessing\Windows\Window.cs:line 130 at MyExample.Program.<>c.

b__4_2(Window2 w) in C:\Users\jonathan.keaveney\Documents\TrillSamples-master\TrillSamples-master\TrillSamples\MyExample\Program.cs:line 125 at Microsoft.StreamProcessing.Streamable.Aggregate[TKey,TInput,TState1,TOutput1,TState2,TOutput2,TOutput](IStreamable2 source, Func2 aggregate1, Func2 aggregate2, Expression`1 merger) in C:\Users\jonathan.keaveney\githubrepo\Trill\Sources\Core\Microsoft.StreamProcessing\StreamableAPI\StreamableExtensionsTemplate.cs:line 2085 at MyExample.Program.Main(String[] args) in C:\Users\jonathan.keaveney\Documents\TrillSamples-master\TrillSamples-master\TrillSamples\MyExample\Program.cs:line 123

I had to make a small change to the ComparerExpressionCache() to resolve.

Cheers, Jonathan

peterfreiling commented 4 years ago

Thanks for finding/fixing!