diff --git a/influxql/functions.go b/influxql/functions.go index ef9704c33e3..e4cae8508dd 100644 --- a/influxql/functions.go +++ b/influxql/functions.go @@ -556,6 +556,10 @@ func ReducePercentile(percentile float64) ReduceFunc { var allValues []float64 for _, v := range values { + if v == nil { + continue + } + vals := v.([]interface{}) for _, v := range vals { allValues = append(allValues, v.(float64)) diff --git a/influxql/functions_test.go b/influxql/functions_test.go index 1f965e256f4..c08ae6ee3c0 100644 --- a/influxql/functions_test.go +++ b/influxql/functions_test.go @@ -98,3 +98,17 @@ func TestInitializeReduceFuncPercentile(t *testing.T) { t.Errorf("InitializedReduceFunc(%v) mismatch. exp %v got %v", c, exp, err.Error()) } } + +func TestReducePercentileNil(t *testing.T) { + + // ReducePercentile should ignore nil values when calculating the percentile + fn := ReducePercentile(100) + input := []interface{}{ + nil, + } + + got := fn(input) + if got != nil { + t.Fatalf("ReducePercentile(100) returned wrong type. exp nil got %v", got) + } +}