Feature/mathandreduce (#41608)

* Added new math functions: round, ceil, floor 
* Added a new reduce function: last.
This commit is contained in:
Marius Bezuidenhout
2022-01-21 20:15:50 +02:00
committed by GitHub
parent 5d0bc9e933
commit 9fc0aee02b
6 changed files with 98 additions and 1 deletions

View File

@@ -69,6 +69,17 @@ func Count(fv *Float64Field) *float64 {
return &f
}
func Last(fv *Float64Field) *float64 {
var f float64
if fv.Len() == 0 {
f = math.NaN()
return &f
}
v := fv.GetValue(fv.Len() - 1)
f = *v
return &f
}
// Reduce turns the Series into a Number based on the given reduction function
func (s Series) Reduce(refID, rFunc string) (Number, error) {
var l data.Labels
@@ -90,6 +101,8 @@ func (s Series) Reduce(refID, rFunc string) (Number, error) {
f = Max(&floatField)
case "count":
f = Count(&floatField)
case "last":
f = Last(&floatField)
default:
return number, fmt.Errorf("reduction %v not implemented", rFunc)
}