Numeric fields only when using numeric aggregates

pull/2548/head
Philip O'Toole 2015-05-12 11:58:18 -07:00
parent dca9859e50
commit 8ac6d80016
2 changed files with 25 additions and 0 deletions

View File

@ -749,6 +749,16 @@ func ReducePercentile(percentile float64) ReduceFunc {
}
}
// IsNumeric returns whether a given aggregate can only be run on numeric fields.
func IsNumeric(c *Call) bool {
switch c.Name {
case "count", "first", "last":
return false
default:
return true
}
}
// MapRawQuery is for queries without aggregates
func MapRawQuery(itr Iterator) interface{} {
var values []*rawQueryMapOutput

15
tx.go
View File

@ -93,6 +93,21 @@ func (tx *tx) CreateMapReduceJobs(stmt *influxql.SelectStatement, tagKeys []stri
}
}
// If a numerical aggregate is requested, ensure it is only performed on numeric data.
for _, a := range stmt.FunctionCalls() {
lit, ok := a.Args[0].(*influxql.VarRef)
if !ok {
return nil, fmt.Errorf("aggregate call didn't contain a field %s", a.String())
}
if influxql.IsNumeric(a) {
f := m.FieldByName(lit.Val)
if f.Type != influxql.Float && f.Type != influxql.Integer {
return nil, fmt.Errorf("aggregate '%s' requires numerical field values. Field '%s' is of type %s",
a.Name, f.Name, f.Type)
}
}
}
// Grab time range from statement.
tmin, tmax := influxql.TimeRange(stmt.Condition)
if tmax.IsZero() {