Skip to content

Commit

Permalink
Merge branch 'pr-738'
Browse files Browse the repository at this point in the history
Close #738. Fix #713
  • Loading branch information
jvshahid committed Jul 22, 2014
2 parents 91078c0 + 673a122 commit e196277
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions engine/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func wrapDefaultValue(defaultValue *parser.Value) (*protocol.FieldValue, error)
v, _ := strconv.Atoi(defaultValue.Name)
value := int64(v)
return &protocol.FieldValue{Int64Value: &value}, nil
case parser.ValueSimpleName:
if defaultValue.Name != "null" {
return nil, fmt.Errorf("Unsupported fill value %s", defaultValue.Name)
}
return nil, nil
default:
return nil, fmt.Errorf("Unknown type %s", defaultValue.Type)
}
Expand Down
45 changes: 45 additions & 0 deletions integration/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2340,3 +2340,48 @@ func (self *DataTestSuite) GroupByYear(c *C) (Fun, Fun) {
c.Assert(maps[1]["count"], Equals, 1.0)
}
}

// Issue #713
// Test various fill options
func (self *DataTestSuite) MeanAggregateFillWithZero(c *C) (Fun, Fun) {
return func(client Client) {
data := `
[
{
"points": [
[1304378375, 10.0],
[1304378380, 20.0],
[1304378400, 60.0]
],
"name": "test_fill_zero",
"columns": ["time", "value"]
}
]`
client.WriteJsonData(data, c, influxdb.Second)
}, func(client Client) {
queries := map[string]interface{}{
"select mean(value) from test_fill_zero group by time(10s)": math.Inf(1),
"select mean(value) from test_fill_zero group by time(10s) fill(0)": 0.0,
"select mean(value) from test_fill_zero group by time(10s) fill(-42)": -42.0,
"select mean(value) from test_fill_zero group by time(10s) fill(42)": 42.0,
"select mean(value) from test_fill_zero group by time(10s) fill(null)": nil,
}

for query, expectedValue := range queries {
serieses := client.RunQuery(query, c)
c.Assert(serieses, HasLen, 1)
maps := ToMap(serieses[0])
c.Assert(maps[0], DeepEquals, map[string]interface{}{"time": 1304378400000.0, "mean": 60.0})
v, ok := expectedValue.(float64)
// we assign math.Inf for the no fill() case
if ok && math.IsInf(v, 1) {
c.Assert(maps[1], DeepEquals, map[string]interface{}{"time": 1304378380000.0, "mean": 20.0})
c.Assert(maps[2], DeepEquals, map[string]interface{}{"time": 1304378370000.0, "mean": 10.0})
continue
}
c.Assert(maps[1], DeepEquals, map[string]interface{}{"time": 1304378390000.0, "mean": expectedValue})
c.Assert(maps[2], DeepEquals, map[string]interface{}{"time": 1304378380000.0, "mean": 20.0})
c.Assert(maps[3], DeepEquals, map[string]interface{}{"time": 1304378370000.0, "mean": 10.0})
}
}
}
1 change: 1 addition & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ func (self *QueryParserSuite) TestParseSelectWithGroupByFillWithZero(c *C) {

groupBy := q.GetGroupByClause()
c.Assert(groupBy.FillWithZero, Equals, true)
c.Assert(groupBy.FillValue.Name, Equals, "0")
c.Assert(groupBy.Elems, HasLen, 2)
c.Assert(groupBy.Elems[0].IsFunctionCall(), Equals, false)
c.Assert(groupBy.Elems[0].Name, Equals, "user_email")
Expand Down

1 comment on commit e196277

@otoolep
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like the tighter unit testing.

Please sign in to comment.