Skip to content

Commit

Permalink
If no points to count, count is 0
Browse files Browse the repository at this point in the history
Fix issue #4701.
  • Loading branch information
otoolep committed Nov 13, 2015
1 parent 76eca03 commit f889ac1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/influxd/run/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,11 @@ func TestServer_Query_Count(t *testing.T) {
command: fmt.Sprintf(`SELECT count(value) FROM db0.rp0.cpu WHERE time >= '%s'`, hour_ago.Format(time.RFC3339Nano)),
exp: fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","count"],"values":[["%s",1]]}]}]}`, hour_ago.Format(time.RFC3339Nano)),
},
&Query{
name: "selecting count(value) with filter that excludes all results should return 0",
command: fmt.Sprintf(`SELECT count(value) FROM db0.rp0.cpu WHERE value=100 AND time >= '%s'`, hour_ago.Format(time.RFC3339Nano)),
exp: fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","columns":["time","count"],"values":[["%s",0]]}]}]}`, hour_ago.Format(time.RFC3339Nano)),
},
&Query{
name: "selecting count(*) should error",
command: `SELECT count(*) FROM db0.rp0.cpu`,
Expand Down
5 changes: 1 addition & 4 deletions tsdb/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ func MapCount(input *MapInput) interface{} {
for range input.Items {
n++
}
if n > 0 {
return n
}
return nil
return n
}

type InterfaceValues []interface{}
Expand Down

0 comments on commit f889ac1

Please sign in to comment.