-
Notifications
You must be signed in to change notification settings - Fork 54
Description
When using the Timeseries queries, there are several ways in which a query can return a result that includes NaN as the value. When this occurs, an exception is thrown due to being unable to convert NaN to a double when calling ToTimeseriesTuple
Examples where a NaN can be a valid result:
- When executing a query using
empty: true, and there are no stored values for a bucket in the range. Official documentation supports this: https://redis.io/docs/latest/commands/ts.range/ - When executing a query where the aggregator is one of the standard deviations (std.s for example) but there are not enough data points to generate the standard deviation value for the bucket.
The library needs to be able to handle legitimate NaN value returns from Redis Timeseries queries. Possible options would be allowing the Timeseries Tuple to store a Null value or by using a (user definable?) default value when a NaN is found (e.g. 0), or by simply filtering out NaN results and not including them in the Array (though this would invalidate the purpose of being able to set the empty flag...).
Exception thrown when NaN Result returned from Redis Query.
Example query:
var start = 1748764800000;
var end = 1751169599999;
var bucket = 86400000;
var key = $"{{{locationId}}}:{equipmentType}:{equipmentId}:{property.ToLower()}";
var aggregate = TsAggregation.StdS;
var res = await timeSeries.RangeAsync(key, start, end, align: start, aggregation: aggregate, timeBucket: bucket, empty: true);
Exception:
Message = "Unable to cast from Raw to double: 'NaN'"
StackTrace = at StackExchange.Redis.RedisValue.op_Explicit(RedisValue value)
at StackExchange.Redis.RedisResult.SingleRedisResult.AsDouble()
at NRedisStack.ResponseParser.ToTimeSeriesTuple(RedisResult result)
at NRedisStack.ResponseParser.<>c__DisplayClass13_0.<ToTimeSeriesTupleArray>b__0(RedisResult tuple)
at System.Array.ForEach[T](T[] array, Action`1 action)
at NRedisStack.ResponseParser.ToTimeSeriesTupleArray(RedisResult result)
at NRedisStack.TimeSeriesCommandsAsync.<RangeAsync>d__18.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at <User Code>