From 9a954daa860aee74b924122d7f02b1bd800d1534 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Thu, 23 Apr 2015 11:10:19 -0600 Subject: [PATCH] Fix panic: interface conversion: interface is nil, not []interface {} Fixes #2374 --- influxql/functions.go | 4 ++++ influxql/functions_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) 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) + } +}