From c69d4b01f0e10b660b300a4cebb65f3a1b963635 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Sun, 23 Feb 2020 18:01:53 +0200 Subject: [PATCH] fix rollupOpen(), rollupHigh(), rollupLow() functions (#328) --- app/vmselect/promql/rollup.go | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/app/vmselect/promql/rollup.go b/app/vmselect/promql/rollup.go index e1a3e0cfd5..48dd0dceff 100644 --- a/app/vmselect/promql/rollup.go +++ b/app/vmselect/promql/rollup.go @@ -1435,12 +1435,9 @@ func getCandlestickValues(rfa *rollupFuncArg) []float64 { } func rollupOpen(rfa *rollupFuncArg) float64 { - if !math.IsNaN(rfa.prevValue) { - return rfa.prevValue - } values := getCandlestickValues(rfa) if len(values) == 0 { - return nan + return rfa.prevValue } return values[0] } @@ -1455,14 +1452,11 @@ func rollupClose(rfa *rollupFuncArg) float64 { func rollupHigh(rfa *rollupFuncArg) float64 { values := getCandlestickValues(rfa) - max := rfa.prevValue - if math.IsNaN(max) { - if len(values) == 0 { - return nan - } - max = values[0] + if len(values) == 0 { + return rfa.prevValue } - for _, v := range values { + max := values[0] + for _, v := range values[1:] { if v > max { max = v } @@ -1472,14 +1466,11 @@ func rollupHigh(rfa *rollupFuncArg) float64 { func rollupLow(rfa *rollupFuncArg) float64 { values := getCandlestickValues(rfa) - min := rfa.prevValue - if math.IsNaN(min) { - if len(values) == 0 { - return nan - } - min = values[0] + if len(values) == 0 { + return rfa.prevValue } - for _, v := range values { + min := values[0] + for _, v := range values[1:] { if v < min { min = v }