-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Execution
-
Fully Compatible
-
ALL
-
-
0
Currently, for a document window like [1, 1], the SBE window stage will add document 0, 1, then remove document 0. This algorithm doesn't work well with the particular implementation of $stdDev on some corner cases. The removable stddev keeps track of the total count and non-finite count in the window frame, but the numeric state is calculated based on the total count. If a non-finite number (NaN, Inf) is added and then removed from the window frame, the total count includes those non-finite numbers and it affects the final numeric result.
The simplest way is to update the $stdDev implementation, so that we do not count non-finite numbers in the window frame during numeric calculation. The result is still correct if there are non-finite numbers in the window frame, because the non-finite count is still tracked and we should just return null. This keeps the stddev result correct yet makes it compatible with the SBE window stage algorithm.