diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec485ed02f..8992ca88d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ There are breaking changes in this release: - [#4685](https://github.com/influxdb/influxdb/pull/4685): Automatically promote node to raft peer if drop server results in removing a raft peer. ### Bugfixes +- [#47778](https://github.com/influxdb/influxdb/pull/4778): If there are points to count, count is 0. Fixes [#4701](https://github.com/influxdb/influxdb/issues/4701) - [#4715](https://github.com/influxdb/influxdb/pull/4715): Fix panic during Raft-close. Fix [issue #4707](https://github.com/influxdb/influxdb/issues/4707). Thanks @oiooj - [#4643](https://github.com/influxdb/influxdb/pull/4643): Fix panic during backup restoration. Thanks @oiooj - [#4632](https://github.com/influxdb/influxdb/pull/4632): Fix parsing of IPv6 hosts in client package. Thanks @miguelxpn diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index 3f633019af1..cfda3be41f0 100644 --- a/cmd/influxd/run/server_test.go +++ b/cmd/influxd/run/server_test.go @@ -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`, @@ -4250,24 +4255,6 @@ func TestServer_Query_Fill(t *testing.T) { exp: `{"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]]}]}]}`, params: url.Values{"db": []string{"db0"}}, }, - &Query{ - name: "fill with count aggregate defaults to null", - command: `select count(val) from fills where time >= '2009-11-10T23:00:00Z' and time < '2009-11-10T23:00:20Z' group by time(5s)`, - exp: `{"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]]}]}]}`, - params: url.Values{"db": []string{"db0"}}, - }, - &Query{ - name: "fill with count aggregate defaults to null, no values match", - command: `select count(val) from fills where time >= '2009-11-10T23:00:00Z' and time < '2009-11-10T23:00:20Z' and val > 100 group by time(5s)`, - exp: `{"results":[{"series":[{"name":"fills","columns":["time","count"],"values":[["2009-11-10T23:00:00Z",null],["2009-11-10T23:00:05Z",null],["2009-11-10T23:00:10Z",null],["2009-11-10T23:00:15Z",null]]}]}]}`, - params: url.Values{"db": []string{"db0"}}, - }, - &Query{ - name: "fill with count aggregate specific value", - command: `select count(val) from fills where time >= '2009-11-10T23:00:00Z' and time < '2009-11-10T23:00:20Z' group by time(5s) fill(1234)`, - exp: `{"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]]}]}]}`, - params: url.Values{"db": []string{"db0"}}, - }, }...) for i, query := range test.queries { diff --git a/tsdb/functions.go b/tsdb/functions.go index 61da27957ed..f10b0cb468f 100644 --- a/tsdb/functions.go +++ b/tsdb/functions.go @@ -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{}