mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00: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
2 changed files with 25 additions and 4 deletions
|
@ -84,18 +84,22 @@ func newBinaryOpFunc(bf func(left, right float64, isBool bool) float64) binaryOp
|
||||||
return func(bfa *binaryOpFuncArg) ([]*timeseries, error) {
|
return func(bfa *binaryOpFuncArg) ([]*timeseries, error) {
|
||||||
left := bfa.left
|
left := bfa.left
|
||||||
right := bfa.right
|
right := bfa.right
|
||||||
switch bfa.be.Op {
|
op := bfa.be.Op
|
||||||
case "ifnot":
|
switch true {
|
||||||
|
case op == "ifnot":
|
||||||
left = removeEmptySeries(left)
|
left = removeEmptySeries(left)
|
||||||
// Do not remove empty series on the right side,
|
// Do not remove empty series on the right side,
|
||||||
// so the left-side series could be matched against them.
|
// 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,
|
// 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,
|
// - if empty time series are removed on the left side,
|
||||||
// then they won't be substituted by time series from the right side.
|
// then they won't be substituted by time series from the right side.
|
||||||
// - if empty time series are removed on 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.
|
// 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:
|
default:
|
||||||
left = removeEmptySeries(left)
|
left = removeEmptySeries(left)
|
||||||
right = removeEmptySeries(right)
|
right = removeEmptySeries(right)
|
||||||
|
|
|
@ -2625,6 +2625,23 @@ func TestExecSuccess(t *testing.T) {
|
||||||
resultExpected := []netstorage.Result{}
|
resultExpected := []netstorage.Result{}
|
||||||
f(q, resultExpected)
|
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.Run(`-1 < 2`, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
q := `-1 < 2`
|
q := `-1 < 2`
|
||||||
|
|
Loading…
Reference in a new issue