Skip to content

Commit

Permalink
Fix panic: interface conversion: interface is nil, not []interface {}
Browse files Browse the repository at this point in the history
Fixes #2374
  • Loading branch information
jwilder committed Apr 23, 2015
1 parent d61377f commit 9a954da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions influxql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 14 additions & 0 deletions influxql/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 9a954da

Please sign in to comment.