Merge pull request #3908 from influxdb/firstopt

only look at the first value for first()
pull/3913/head
Daniel Morsing 2015-08-31 14:21:29 -07:00
commit 841e6fc6b5
1 changed files with 12 additions and 20 deletions

View File

@ -935,29 +935,21 @@ type firstLastMapOutput struct {
} }
// MapFirst collects the values to pass to the reducer // MapFirst collects the values to pass to the reducer
// This function assumes time ordered input
func MapFirst(itr Iterator) interface{} { func MapFirst(itr Iterator) interface{} {
out := &firstLastMapOutput{} k, v := itr.Next()
pointsYielded := false if k == -1 {
for k, v := itr.Next(); k != -1; k, v = itr.Next() {
// Initialize first
if !pointsYielded {
out.Time = k
out.Val = v
pointsYielded = true
}
if k < out.Time {
out.Time = k
out.Val = v
} else if k == out.Time && greaterThan(v, out.Val) {
out.Val = v
}
}
if pointsYielded {
return out
}
return nil return nil
} }
nextk, nextv := itr.Next()
for nextk == k {
if greaterThan(nextv, v) {
v = nextv
}
nextk, nextv = itr.Next()
}
return &firstLastMapOutput{k, v}
}
// ReduceFirst computes the first of value. // ReduceFirst computes the first of value.
func ReduceFirst(values []interface{}) interface{} { func ReduceFirst(values []interface{}) interface{} {