Skip to content

Commit

Permalink
fix #55. Limit should limit the points that match the Where clause
Browse files Browse the repository at this point in the history
  • Loading branch information
jvshahid committed Nov 14, 2013
1 parent 0d8667e commit a6424bc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
- [Issue #45](https://github.com/influxdb/influxdb/issues/45). Aggregation shouldn't mess up the order of the points
- [Issue #44](https://github.com/influxdb/influxdb/issues/44). Fix crashes on RHEL 5.9
- [Issue #34](https://github.com/influxdb/influxdb/issues/34). Ascending order always return null for columns that have a null value
- [Issue #55](https://github.com/influxdb/influxdb/issues/55). Limit should limit the points that match the Where clause

### Deprecated

Expand Down
24 changes: 24 additions & 0 deletions src/datastore/datastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,30 @@ func (self *DatastoreSuite) TestNullValues(c *C) {
c.Assert(results[0].Points, HasLen, 4)
}

func (self *DatastoreSuite) TestLimitShouldLimitPointsThatMatchTheFilter(c *C) {
cleanup(nil)
db := newDatastore(c)
defer cleanup(db)

minuteAgo := time.Now().Add(-time.Minute).Unix()
mock := `{
"points":[
{"values":[{"string_value": "paul"}, {"string_value": "dix"}],"sequence_number":1},
{"values":[{"string_value":"todd"}, {"string_value": "persen"}],"sequence_number":2}],
"name":"user_things",
"fields":["first_name", "last_name"]
}`
series := stringToSeries(mock, minuteAgo, c)
err := db.WriteSeriesData("foobar", series)
c.Assert(err, IsNil)
user := &MockUser{}
results := executeQuery(user, "foobar", "select last_name from user_things where first_name == 'paul' limit 1", db, c)
c.Assert(results, HasLen, 1)
c.Assert(results[0].Points, HasLen, 1)
c.Assert(results[0].Points[0].Values, HasLen, 1)
c.Assert(*results[0].Points[0].Values[0].StringValue, Equals, "dix")
}

func (self *DatastoreSuite) TestCanDeleteARangeOfData(c *C) {
cleanup(nil)
db := newDatastore(c)
Expand Down
4 changes: 3 additions & 1 deletion src/datastore/leveldb_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,10 @@ func (self *LevelDbDatastore) executeQueryForSeries(database, series string, col
resultByteCount += 16

// check if we should send the batch along
if resultByteCount > MAX_SERIES_SIZE {
if resultByteCount > MAX_SERIES_SIZE || limit < 1 {
lengthBeforeFiltering := len(result.Points)
filteredResult, _ := Filter(query, result)
limit += lengthBeforeFiltering - len(filteredResult.Points)
if err := yield(filteredResult); err != nil {
return err
}
Expand Down
25 changes: 25 additions & 0 deletions src/integration/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,31 @@ func (self *IntegrationSuite) TestAscendingQueries(c *C) {
}
}

// issue #55
func (self *IntegrationSuite) TestFilterWithLimit(c *C) {
for i := 0; i < 3; i++ {
err := self.server.WriteData(fmt.Sprintf(`
[
{
"name": "test_ascending",
"columns": ["cpu", "host"],
"points": [[%d, "hosta"], [%d, "hostb"]]
}
]
`, 60+i*10, 70+i*10))
c.Assert(err, IsNil)
time.Sleep(1 * time.Second)
}
bs, err := self.server.RunQuery("select host, cpu from test_ascending where host == 'hostb' order asc limit 1")
c.Assert(err, IsNil)
data := []*h.SerializedSeries{}
err = json.Unmarshal(bs, &data)
c.Assert(data, HasLen, 1)
c.Assert(data[0].Name, Equals, "test_ascending")
c.Assert(data[0].Columns, HasLen, 4)
c.Assert(data[0].Points, HasLen, 1)
}

func (self *IntegrationSuite) TestCountWithGroupBy(c *C) {
for i := 0; i < 20; i++ {
err := self.server.WriteData(fmt.Sprintf(`
Expand Down

0 comments on commit a6424bc

Please sign in to comment.