Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for LT, LTE, GT, GTE #1827

Merged
merged 1 commit into from
Mar 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ func (m *Measurement) walkWhereForSeriesIds(expr influxql.Expr, filters map[uint
switch n := expr.(type) {
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.EQREGEX || n.Op == influxql.NEQREGEX {
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 {
ids, shouldInclude, expr := m.idsForExpr(n)
for _, id := range ids {
filters[id] = expr
Expand Down
60 changes: 58 additions & 2 deletions httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,8 @@ func TestHandler_serveWriteSeriesWhereIntField(t *testing.T) {
s := NewHTTPServer(srvr)
defer s.Close()

status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "timestamp": "2009-11-10T23:00:02Z", "fields": {"load": 100}}]}`)
status, body := MustHTTP("POST", s.URL+`/write`, nil, nil, `{"database" : "foo", "retentionPolicy" : "bar", "points": [{"name": "cpu", "timestamp": "2009-11-10T23:00:02Z", "fields": {"load": 100}},
{"name": "cpu", "timestamp": "2009-11-10T23:01:02Z", "fields": {"load": 80}}]}`)
if status != http.StatusOK {
t.Logf("body %s\n", body)
t.Fatalf("unexpected status: %d", status)
Expand All @@ -1478,7 +1479,29 @@ func TestHandler_serveWriteSeriesWhereIntField(t *testing.T) {

srvr.Restart() // Ensure data is queryable across restarts.

query := map[string]string{"db": "foo", "q": "select load from cpu where load = 100"}
query := map[string]string{"db": "foo", "q": "select load from cpu where load > 100"}
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusOK {
t.Logf("query %s\n", query)
t.Log(body)
t.Errorf("unexpected status: %d", status)
}
if string(body) != `{"results":[{}]}` {
t.Fatalf("unexpected results, got %s", string(body))
}

query = map[string]string{"db": "foo", "q": "select load from cpu where load >= 100"}
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusOK {
t.Logf("query %s\n", query)
t.Log(body)
t.Errorf("unexpected status: %d", status)
}
if string(body) != `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100]]}]}]}` {
t.Fatalf("unexpected results, got %s", string(body))
}

query = map[string]string{"db": "foo", "q": "select load from cpu where load = 100"}
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusOK {
t.Logf("query %s\n", query)
Expand All @@ -1489,6 +1512,17 @@ func TestHandler_serveWriteSeriesWhereIntField(t *testing.T) {
t.Fatalf("unexpected results, got %s", string(body))
}

query = map[string]string{"db": "foo", "q": "select load from cpu where load <= 100"}
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusOK {
t.Logf("query %s\n", query)
t.Log(body)
t.Errorf("unexpected status: %d", status)
}
if string(body) != `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:00:02Z",100],["2009-11-10T23:01:02Z",80]]}]}]}` {
t.Fatalf("unexpected results, got %s", string(body))
}

query = map[string]string{"db": "foo", "q": "select load from cpu where load > 99"}
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusOK {
Expand All @@ -1510,6 +1544,28 @@ func TestHandler_serveWriteSeriesWhereIntField(t *testing.T) {
if string(body) != `{"results":[{}]}` {
t.Fatalf("unexpected results, got %s", string(body))
}

query = map[string]string{"db": "foo", "q": "select load from cpu where load < 99"}
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusOK {
t.Logf("query %s\n", query)
t.Log(body)
t.Errorf("unexpected status: %d", status)
}
if string(body) != `{"results":[{"series":[{"name":"cpu","columns":["time","load"],"values":[["2009-11-10T23:01:02Z",80]]}]}]}` {
t.Fatalf("unexpected results, got %s", string(body))
}

query = map[string]string{"db": "foo", "q": "select load from cpu where load < 80"}
status, body = MustHTTP("GET", s.URL+`/query`, query, nil, "")
if status != http.StatusOK {
t.Logf("query %s\n", query)
t.Log(body)
t.Errorf("unexpected status: %d", status)
}
if string(body) != `{"results":[{}]}` {
t.Fatalf("unexpected results, got %s", string(body))
}
}

func TestHandler_serveWriteSeriesWhereStringField(t *testing.T) {
Expand Down