Fix #539. count(distinct()) with fill shouldn't panic on empty groups

pull/546/head
John Shahid 2014-05-13 16:46:45 -04:00
parent ad7bfa7aa0
commit 9f95a44e3d
2 changed files with 21 additions and 1 deletions

View File

@ -243,7 +243,10 @@ func (self *CompositeAggregator) CalculateSummaries(state interface{}) {
} }
func (self *CompositeAggregator) GetValues(state interface{}) [][]*protocol.FieldValue { func (self *CompositeAggregator) GetValues(state interface{}) [][]*protocol.FieldValue {
s := state.(*CompositeAggregatorState) s, ok := state.(*CompositeAggregatorState)
if !ok {
return self.left.GetValues(nil)
}
return self.left.GetValues(s.leftState) return self.left.GetValues(s.leftState)
} }

View File

@ -485,6 +485,23 @@ func (self *DataTestSuite) DifferentColumnsInOnePost(c *C) (Fun, Fun) {
} }
} }
func (self *DataTestSuite) FillWithCountDistinct(c *C) (Fun, Fun) {
return func(client Client) {
t1 := time.Now()
t2 := t1.Add(-2 * time.Hour)
data := fmt.Sprintf(`[{"name":"foo","columns":["time", "val0"],"points":[[%d, "a"],[%d, "b"]]}]`, t1.Unix(), t2.Unix())
client.WriteJsonData(data, c, "s")
}, func(client Client) {
series := client.RunQuery("select count(distinct(val0)) from foo group by time(1h) fill(0)", c, "m")
c.Assert(series, HasLen, 1)
maps := ToMap(series[0])
c.Assert(maps, HasLen, 3)
c.Assert(maps[0]["count"], Equals, 1.0)
c.Assert(maps[1]["count"], Equals, 0.0)
c.Assert(maps[2]["count"], Equals, 1.0)
}
}
func (self *DataTestSuite) ExplainsWithLocalAggregatorAndRegex(c *C) (Fun, Fun) { func (self *DataTestSuite) ExplainsWithLocalAggregatorAndRegex(c *C) (Fun, Fun) {
return func(client Client) { return func(client Client) {
data := ` data := `