fix . Limit should limit the points that match the Where clause

pull/57/head v0.1.1.rc5
John Shahid 2013-11-14 16:12:33 -05:00
parent 0d8667e7fe
commit a6424bcf44
4 changed files with 53 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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