Skip to content

Commit

Permalink
Merge pull request #2295 from influxdb/check_null_fix
Browse files Browse the repository at this point in the history
Use nil as default return value for MapCount
  • Loading branch information
toddboom committed Apr 15, 2015
2 parents 6f9e639 + 7147b0f commit eb2eee2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [#2276](https://github.com/influxdb/influxdb/pull/2276): Broker topic truncation.
- [#2292](https://github.com/influxdb/influxdb/pull/2292): Wire up drop CQ statement - thanks @neonstalwart!
- [#2290](https://github.com/influxdb/influxdb/pull/2290): Allow hostname argument to override default config - thanks @neonstalwart!
- [#2295](https://github.com/influxdb/influxdb/pull/2295): Use nil as default return value for MapCount - thanks @neonstalwart!

## v0.9.0-rc24 [2015-04-13]

Expand Down
10 changes: 10 additions & 0 deletions cmd/influxd/server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,16 @@ 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]]}]}]}`,
},
{
name: "fill with count aggregate specific value",
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) fill(1234)`,
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",1234],["2009-11-10T23:00:15Z",1]]}]}]}`,
},

// Drop Measurement, series tags preserved tests
{
Expand Down
7 changes: 5 additions & 2 deletions influxql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit eb2eee2

Please sign in to comment.