Also include NEQ in filters

This fixes != for field value comparisons.
pull/2104/head
Philip O'Toole 2015-03-27 17:29:14 -07:00 committed by Philip O'Toole
parent d6613d7e9d
commit 1b700264a7
3 changed files with 33 additions and 1 deletions

View File

@ -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"}}]}`,

View File

@ -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

View File

@ -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 /<regex>/
{