diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 9bb63b890..2d8a4abbc 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -526,6 +526,17 @@ func TestExecSuccess(t *testing.T) { resultExpected := []netstorage.Result{r} f(q, resultExpected) }) + t.Run(`minute(series_with_NaNs)`, func(t *testing.T) { + t.Parallel() + q := `minute(time() <= 1200 or time() > 1600)` + r := netstorage.Result{ + MetricName: metricNameExpected, + Values: []float64{16, 20, nan, nan, 30, 33}, + Timestamps: timestampsExpected, + } + resultExpected := []netstorage.Result{r} + f(q, resultExpected) + }) t.Run("rate({})", func(t *testing.T) { t.Parallel() q := `rate({})` diff --git a/app/vmselect/promql/transform.go b/app/vmselect/promql/transform.go index 660f8bb8e..8d350dc29 100644 --- a/app/vmselect/promql/transform.go +++ b/app/vmselect/promql/transform.go @@ -265,6 +265,9 @@ func newTransformFuncDateTime(f func(t time.Time) int) transformFunc { } tf := func(values []float64) { for i, v := range values { + if math.IsNaN(v) { + continue + } t := time.Unix(int64(v), 0).UTC() values[i] = float64(f(t)) } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fc9d2b3ae..43c291865 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,7 +7,9 @@ * 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. * BUGFIX: properly parse hex numbers in MetricsQL. Previously hex numbers with non-decimal digits such as `0x3b` couldn't be parsed. -* BUGFIX: Handle `time() cmp_op metric` like Prometheus does - i.e. return `metric` value if `cmp_op` comparison is true. Previously `time()` value was returned. +* BUGFIX: handle `time() cmp_op metric` like Prometheus does - i.e. return `metric` value if `cmp_op` comparison is true. Previously `time()` value was returned. +* BUGFIX: return `nan` for `minute(m)` query when `m` equals to `nan` like Prometheus does. This applies to all the time-related functions such as `day_of_month`, `day_of_week`, + `days_in_month`, `hour`, `month` and `year`. # [v1.48.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.48.0)