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:
Aliaksandr Valialkin 2022-04-21 14:55:35 +03:00
parent a5cfe5d13e
commit bc54ae9608
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 25 additions and 4 deletions

View File

@ -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)

View File

@ -2635,6 +2635,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`