diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index 86f40f6c41a..79bb95bef96 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -912,6 +912,11 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent query: `select mean(val) from "%DB%"."%RP%".fills where time >= '2009-11-10T23:00:00Z' and time < '2009-11-10T23:00:20Z' group by time(5s)`, expected: `{"results":[{"series":[{"name":"fills","columns":["time","mean"],"values":[["2009-11-10T23:00:00Z",4],["2009-11-10T23:00:05Z",4],["2009-11-10T23:00:10Z",null],["2009-11-10T23:00:15Z",10]]}]}]}`, }, + { + name: "fill with count aggregate defaults to null", + query: `select count(val) from "%DB%"."%RP%".fills where time >= '2009-11-10T23:00:00Z' and time < '2009-11-10T23:00:20Z' group by time(5s)`, + expected: `{"results":[{"series":[{"name":"fills","columns":["time","count"],"values":[["2009-11-10T23:00:00Z",2],["2009-11-10T23:00:05Z",1],["2009-11-10T23:00:10Z",null],["2009-11-10T23:00:15Z",1]]}]}]}`, + }, // Drop Measurement, series tags preserved tests { diff --git a/influxql/functions.go b/influxql/functions.go index 33cbde18372..740c44f01bd 100644 --- a/influxql/functions.go +++ b/influxql/functions.go @@ -165,11 +165,14 @@ func InitializeUnmarshaller(c *Call) (UnmarshalFunc, error) { // MapCount computes the number of values in an iterator. func MapCount(itr Iterator) interface{} { - n := 0 + n := float64(0) for _, k, _ := itr.Next(); k != 0; _, k, _ = itr.Next() { n++ } - return float64(n) + if n > 0 { + return n + } + return nil } // MapSum computes the summation of values in an iterator.