From b7000c80ddb64c77051823d8c0acc8bfbac9cf99 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Wed, 9 Dec 2015 15:20:47 -0700 Subject: [PATCH] count with fill(none) will drop 0 valued intervals --- CHANGELOG.md | 1 + cmd/influxd/run/server_test.go | 18 ++++++++++++++++++ tsdb/aggregate.go | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5456fc58..effe86ce73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features ### Bugfixes +- [#5042](https://github.com/influxdb/influxdb/issues/5042): Count with fill(none) will drop 0 valued intervals. - [#5016](https://github.com/influxdb/influxdb/pull/5016): Don't panic if Meta data directory not writable. Thanks @oiooj - [#5059](https://github.com/influxdb/influxdb/pull/5059): Fix unmarshal of database error by client code. Thanks @farshidtz - [#4940](https://github.com/influxdb/influxdb/pull/4940): Fix distributed aggregate query query error. Thanks @li-ang diff --git a/cmd/influxd/run/server_test.go b/cmd/influxd/run/server_test.go index 7e72b8b046..18cd62dd7b 100644 --- a/cmd/influxd/run/server_test.go +++ b/cmd/influxd/run/server_test.go @@ -4377,6 +4377,24 @@ 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 defaults to 0 for count", + 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",0],["2009-11-10T23:00:15Z",1]]}]}]}`, + params: url.Values{"db": []string{"db0"}}, + }, + &Query{ + name: "fill none drops 0s for count", + 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(none)`, + 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:15Z",1]]}]}]}`, + params: url.Values{"db": []string{"db0"}}, + }, + &Query{ + name: "fill previous overwrites 0s for count", + 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(previous)`, + 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",1],["2009-11-10T23:00:15Z",1]]}]}]}`, + params: url.Values{"db": []string{"db0"}}, + }, }...) for i, query := range test.queries { diff --git a/tsdb/aggregate.go b/tsdb/aggregate.go index f43551b184..90bf017a71 100644 --- a/tsdb/aggregate.go +++ b/tsdb/aggregate.go @@ -322,6 +322,7 @@ func (e *AggregateExecutor) processFill(results [][]interface{}) [][]interface{} return results } + isCount := e.stmt.HasSimpleCount() if e.stmt.Fill == influxql.NoFill { // remove any rows that have even one nil value. This one is tricky because they could have multiple // aggregates, but this option means that any row that has even one nil gets purged. @@ -330,7 +331,7 @@ func (e *AggregateExecutor) processFill(results [][]interface{}) [][]interface{} hasNil := false // start at 1 because the first value is always time for j := 1; j < len(vals); j++ { - if vals[j] == nil { + if vals[j] == nil || (isCount && isZero(vals[j])) { hasNil = true break } @@ -342,7 +343,6 @@ func (e *AggregateExecutor) processFill(results [][]interface{}) [][]interface{} return newResults } - isCount := e.stmt.HasSimpleCount() // They're either filling with previous values or a specific number for i, vals := range results { // start at 1 because the first value is always time