diff --git a/index.go b/index.go index b11efacb1a..0b3fb0f23a 100644 --- a/index.go +++ b/index.go @@ -210,7 +210,22 @@ func (m measurementIndex) seriesByTags(tags map[string]string) *Series { func (m measurementIndex) seriesIDs(filter *Filter) (ids SeriesIDs) { values := m.tagsToSeries[filter.Key] if values != nil { + // this is for the value is not null query + if filter.Not && filter.Value == "" { + for _, v := range values { + if ids == nil { + ids = v + } else { + ids.Intersect(v) + } + } + return + } + + // get the ids that have the given key/value tag pair ids = SeriesIDs(values[filter.Value]) + + // filter out these ids from the entire set if it's a not query if filter.Not { ids = m.ids.Reject(ids) } diff --git a/index_test.go b/index_test.go index 45f251137c..e497bb0f01 100644 --- a/index_test.go +++ b/index_test.go @@ -158,7 +158,7 @@ func TestIndex_SeriesIDsWhereFilter(t *testing.T) { // match against no tags { names: []string{"cpu_load", "redis"}, - result: []uint32{uint32(1), uint32(2), uint32(3), uint32(4), uint32(5)}, + result: []uint32{uint32(1), uint32(2), uint32(3), uint32(4), uint32(5), uint32(6)}, }, // match against all tags @@ -217,6 +217,13 @@ func TestIndex_SeriesIDsWhereFilter(t *testing.T) { }, // query against a tag NOT null + { + names: []string{"queue_depth"}, + filters: []*influxdb.Filter{ + &influxdb.Filter{Key: "app", Value: "", Not: true}, + }, + result: []uint32{uint32(6)}, + }, // query against a tag value and a NOT value on the same key @@ -330,6 +337,15 @@ func indexWithFixtureData() *influxdb.Index { return nil } + s = &influxdb.Series{ + ID: uint32(6), + Tags: map[string]string{"name": "high priority", "app": "paultown"}} + + added = idx.AddSeries("queue_depth", s) + if !added { + return nil + } + return idx }