diff --git a/app/vmselect/promql/binary_op.go b/app/vmselect/promql/binary_op.go index d262823303..7d827607a1 100644 --- a/app/vmselect/promql/binary_op.go +++ b/app/vmselect/promql/binary_op.go @@ -62,6 +62,9 @@ func newBinaryOpCmpFunc(cf func(left, right float64) bool) binaryOpFunc { if cf(left, right) { return 1 } + if math.IsNaN(left) { + return nan + } return 0 } return newBinaryOpFunc(cfe) diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 1aac301db9..d0cccb5ecc 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -1782,10 +1782,32 @@ func TestExecSuccess(t *testing.T) { }) t.Run(`time() > scalar`, func(t *testing.T) { t.Parallel() - q := `time() > 123` + q := `time() > 1234` r := netstorage.Result{ MetricName: metricNameExpected, - Values: []float64{1000, 1200, 1400, 1600, 1800, 2000}, + Values: []float64{nan, nan, 1400, 1600, 1800, 2000}, + Timestamps: timestampsExpected, + } + resultExpected := []netstorage.Result{r} + f(q, resultExpected) + }) + t.Run(`time() >bool scalar`, func(t *testing.T) { + t.Parallel() + q := `time() >bool 1234` + r := netstorage.Result{ + MetricName: metricNameExpected, + Values: []float64{0, 0, 1, 1, 1, 1}, + Timestamps: timestampsExpected, + } + resultExpected := []netstorage.Result{r} + f(q, resultExpected) + }) + t.Run(`nan >bool scalar1`, func(t *testing.T) { + t.Parallel() + q := `(time() > 1234) >bool 1450` + r := netstorage.Result{ + MetricName: metricNameExpected, + Values: []float64{nan, nan, 0, 1, 1, 1}, Timestamps: timestampsExpected, } resultExpected := []netstorage.Result{r} diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b26e747782..1354d263e7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,8 @@ * BUGFIX: properly parse timestamps in OpenMetrics format - they are exposed as floating-point number in seconds instead of integer milliseconds unlike in Prometheus exposition format. See [the docs](https://github.com/OpenObservability/OpenMetrics/blob/master/specification/OpenMetrics.md#timestamps). +* BUGFIX: return `nan` for `a >bool b` query when `a` equals to `nan` like Prometheus does. Previously `0` was returned in this case. This applies to any comparison operation + with `bool` modifier. See [these docs](https://prometheus.io/docs/prometheus/latest/querying/operators/#comparison-binary-operators) for details. # [v1.48.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.48.0)