Skip to content

Commit

Permalink
Check if the tag filter is a NOT
Browse files Browse the repository at this point in the history
If so, then return all series IDs which do not match.

Fix for issue #2097
  • Loading branch information
otoolep committed Mar 31, 2015
1 parent ef409d6 commit 70d57d3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [#2100](https://github.com/influxdb/influxdb/pull/2100): Synchronize access to shard index.
- [#2131](https://github.com/influxdb/influxdb/pull/2131): Optimize marshalTags().
- [#2130](https://github.com/influxdb/influxdb/pull/2130): Make fewer calls to marshalTags().
- [#2105](https://github.com/influxdb/influxdb/pull/2105): Support != for tag values. Fix issue #2097, thanks to @smonkewitz for bug report.

## v0.9.0-rc17 [2015-03-29]

Expand Down
31 changes: 30 additions & 1 deletion cmd/influxd/server_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,8 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
reset: true,
name: "WHERE tags SELECT single field (EQ tag value1)",
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [{"name": "cpu", "timestamp": "2015-02-28T01:03:36.703820946Z", "tags": {"host": "server01"}, "fields": {"value": 100}},
{"name": "cpu", "timestamp": "2010-02-28T01:03:37.703820946Z", "tags": {"host": "server02"}, "fields": {"value": 200}}]}`,
{"name": "cpu", "timestamp": "2010-02-28T01:03:37.703820946Z", "tags": {"host": "server02"}, "fields": {"value": 200}},
{"name": "cpu", "timestamp": "2012-02-28T01:03:38.703820946Z", "tags": {"host": "server03"}, "fields": {"value": 300}}]}`,
query: `SELECT value FROM "%DB%"."%RP%".cpu WHERE host = 'server01'`,
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["2015-02-28T01:03:36.703820946Z",100]]}]}]}`,
},
Expand All @@ -602,6 +603,34 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent
query: `SELECT value FROM "%DB%"."%RP%".cpu WHERE host = 'server02'`,
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["2010-02-28T01:03:37.703820946Z",200]]}]}]}`,
},
{
name: "WHERE tags SELECT single field (NEQ tag value1)",
query: `SELECT value FROM "%DB%"."%RP%".cpu WHERE host != 'server01'`,
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["2010-02-28T01:03:37.703820946Z",200],["2012-02-28T01:03:38.703820946Z",300]]}]}]}`,
},
{
name: "WHERE tags SELECT single field (NEQ tag value1 AND NEQ tag value2)",
query: `SELECT value FROM "%DB%"."%RP%".cpu WHERE host != 'server01' AND host != 'server02'`,
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["2012-02-28T01:03:38.703820946Z",300]]}]}]}`,
},
{
name: "WHERE tags SELECT single field (NEQ tag value1 OR NEQ tag value2)",
query: `SELECT value FROM "%DB%"."%RP%".cpu WHERE host != 'server01' OR host != 'server02'`, // Yes, this is always true, but that's the point.
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["2010-02-28T01:03:37.703820946Z",200],["2012-02-28T01:03:38.703820946Z",300],["2015-02-28T01:03:36.703820946Z",100]]}]}]}`,
},
{
name: "WHERE tags SELECT single field (NEQ tag value1 AND NEQ tag value2 AND NEQ tag value3)",
query: `SELECT value FROM "%DB%"."%RP%".cpu WHERE host != 'server01' AND host != 'server02' AND host != 'server03'`,
expected: `{"results":[{}]}`,
},
{
reset: true,
name: "WHERE tags SELECT single field (NEQ tag value1, point without any tags)",
write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [{"name": "cpu", "timestamp": "2015-02-28T01:03:36.703820946Z", "tags": {"host": "server01"}, "fields": {"value": 100}},
{"name": "cpu", "timestamp": "2012-02-28T01:03:38.703820946Z", "fields": {"value": 200}}]}`,
query: `SELECT value FROM "%DB%"."%RP%".cpu WHERE host != 'server01'`,
expected: `{"results":[{"series":[{"name":"cpu","columns":["time","value"],"values":[["2012-02-28T01:03:38.703820946Z",200]]}]}]}`,
},

// WHERE fields queries
{
Expand Down
12 changes: 10 additions & 2 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,17 @@ func (m *Measurement) idsForExpr(n *influxql.BinaryExpr) (seriesIDs, bool, influ
return nil, true, nil
}

// if we're looking for series with a specific tag value
// if we're looking for series with specific tag values
if str, ok := value.(*influxql.StringLiteral); ok {
return tagVals[str.Val], true, nil
var ids seriesIDs

if n.Op == influxql.EQ {
// return series that have a tag of specific value.
ids = tagVals[str.Val]
} else if n.Op == influxql.NEQ {
ids = m.seriesIDs.reject(tagVals[str.Val])
}
return ids, true, nil
}

// if we're looking for series with tag values that match a regex
Expand Down

0 comments on commit 70d57d3

Please sign in to comment.