diff --git a/cmd/influxd/server_integration_test.go b/cmd/influxd/server_integration_test.go index 61b3b37fea..cf8703fd25 100644 --- a/cmd/influxd/server_integration_test.go +++ b/cmd/influxd/server_integration_test.go @@ -588,6 +588,21 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent expected: `{"results":[{"series":[{"name":"cpu","tags":{"region":"us-east"},"columns":["time","mean"],"values":[["1970-01-01T00:00:00Z",15]]},{"name":"cpu","tags":{"region":"us-west"},"columns":["time","mean"],"values":[["1970-01-01T00:00:00Z",30]]}]}]}`, }, + // WHERE tag queries + { + 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}}]}`, + 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]]}]}]}`, + }, + { + name: "WHERE tags SELECT single field (EQ tag value2)", + 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]]}]}]}`, + }, + // WHERE fields queries { reset: true, @@ -645,6 +660,10 @@ func runTestsData(t *testing.T, testName string, nodes Cluster, database, retent query: `select load from "%DB%"."%RP%".cpu where load < 80`, expected: `{"results":[{"series":[{"name":"cpu","columns":["time","load"]}]}]}`, }, + { + query: `select load from "%DB%"."%RP%".cpu where load != 100`, + expected: `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:01:02Z",80]]}]}]}`, + }, { write: `{"database" : "%DB%", "retentionPolicy" : "%RP%", "points": [{"name": "logs", "timestamp": "2009-11-10T23:00:02Z","fields": {"event": "disk full"}}, {"name": "logs", "timestamp": "2009-11-10T23:02:02Z","fields": {"event": "disk not full"}}]}`, diff --git a/database.go b/database.go index 54d7479b32..a02d97ae0a 100644 --- a/database.go +++ b/database.go @@ -406,7 +406,7 @@ func (m *Measurement) walkWhereForSeriesIds(expr influxql.Expr, filters map[uint case *influxql.BinaryExpr: // if it's EQ then it's either a field expression or against a tag. we can return this if n.Op == influxql.EQ || n.Op == influxql.LT || n.Op == influxql.LTE || n.Op == influxql.GT || - n.Op == influxql.GTE || n.Op == influxql.EQREGEX || n.Op == influxql.NEQREGEX { + n.Op == influxql.GTE || n.Op == influxql.NEQ || n.Op == influxql.EQREGEX || n.Op == influxql.NEQREGEX { ids, shouldInclude, expr := m.idsForExpr(n) for _, id := range ids { filters[id] = expr diff --git a/influxql/parser_test.go b/influxql/parser_test.go index d9aff7e2fe..3c7e8dbe02 100644 --- a/influxql/parser_test.go +++ b/influxql/parser_test.go @@ -221,6 +221,19 @@ func TestParser_ParseStatement(t *testing.T) { }, }, }, + { + s: `SELECT * FROM cpu WHERE load != 100`, + stmt: &influxql.SelectStatement{ + IsRawQuery: true, + Fields: []*influxql.Field{{Expr: &influxql.Wildcard{}}}, + Sources: []influxql.Source{&influxql.Measurement{Name: "cpu"}}, + Condition: &influxql.BinaryExpr{ + Op: influxql.NEQ, + LHS: &influxql.VarRef{Val: "load"}, + RHS: &influxql.NumberLiteral{Val: 100}, + }, + }, + }, // SELECT * FROM // {