mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 20:37:12 +01:00
app/vmselect/promql: fix comparison to nan
The comparison to nan has been broken in d335cc886c
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/150
This commit is contained in:
parent
de892239a9
commit
d1a9fac894
@ -84,18 +84,22 @@ func newBinaryOpFunc(bf func(left, right float64, isBool bool) float64) binaryOp
|
||||
return func(bfa *binaryOpFuncArg) ([]*timeseries, error) {
|
||||
left := bfa.left
|
||||
right := bfa.right
|
||||
switch bfa.be.Op {
|
||||
case "ifnot":
|
||||
op := bfa.be.Op
|
||||
switch true {
|
||||
case op == "ifnot":
|
||||
left = removeEmptySeries(left)
|
||||
// Do not remove empty series on the right side,
|
||||
// so the left-side series could be matched against them.
|
||||
case "default":
|
||||
case op == "default":
|
||||
// Do not remove empty series on the left and the right side,
|
||||
// since this may result in missing result:
|
||||
// since this may lead to missing result:
|
||||
// - if empty time series are removed on the left side,
|
||||
// then they won't be substituted by time series from the right side.
|
||||
// - if empty time series are removed on the right side,
|
||||
// then this may result in missing time series from the left side.
|
||||
case metricsql.IsBinaryOpCmp(op):
|
||||
// Do not remove empty series for comparison operations,
|
||||
// since this may lead to missing result.
|
||||
default:
|
||||
left = removeEmptySeries(left)
|
||||
right = removeEmptySeries(right)
|
||||
|
@ -2625,6 +2625,23 @@ func TestExecSuccess(t *testing.T) {
|
||||
resultExpected := []netstorage.Result{}
|
||||
f(q, resultExpected)
|
||||
})
|
||||
t.Run(`compare_to_nan_right`, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
q := `1 != nan`
|
||||
r := netstorage.Result{
|
||||
MetricName: metricNameExpected,
|
||||
Values: []float64{1, 1, 1, 1, 1, 1},
|
||||
Timestamps: timestampsExpected,
|
||||
}
|
||||
resultExpected := []netstorage.Result{r}
|
||||
f(q, resultExpected)
|
||||
})
|
||||
t.Run(`compare_to_nan_left`, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
q := `nan != 1`
|
||||
resultExpected := []netstorage.Result{}
|
||||
f(q, resultExpected)
|
||||
})
|
||||
t.Run(`-1 < 2`, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
q := `-1 < 2`
|
||||
|
Loading…
Reference in New Issue
Block a user