From f889ac1140c20fbe506d3918dfc4b4127d351170 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Thu, 12 Nov 2015 18:52:58 -0800 Subject: [PATCH] If no points to count, count is 0 Fix issue #4701. --- cmd/influxd/run/server_test.go | 5 +++++ tsdb/functions.go | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index 3f633019af..68669c320d 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`, diff --git a/tsdb/functions.go b/tsdb/functions.go index 61da27957e..f10b0cb468 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{}