-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spread #1591
Spread #1591
Changes from 3 commits
3dd53eb
28202dd
7c12afb
61d4cd6
2d638b5
b0046bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,8 @@ func (p *Planner) planCall(e *Executor, c *Call) (Processor, error) { | |
mapFn, reduceFn = MapMin, ReduceMin | ||
case "max": | ||
mapFn, reduceFn = MapMax, ReduceMax | ||
case "spread": | ||
mapFn, reduceFn = MapSpread, ReduceSpread | ||
case "stddev": | ||
mapFn, reduceFn = MapStddev, ReduceStddev | ||
case "first": | ||
|
@@ -753,6 +755,53 @@ func ReduceMax(key Key, values []interface{}, e *Emitter) { | |
} | ||
} | ||
|
||
type spreadMapOutput struct { | ||
min, max float64 | ||
} | ||
|
||
// MapSpread collects the values to pass to the reducer | ||
func MapSpread(itr Iterator, e *Emitter, tmax int64) { | ||
var out spreadMapOutput | ||
pointsYielded := false | ||
|
||
for k, v := itr.Next(); k != 0; k, v = itr.Next() { | ||
val := v.(float64) | ||
// Initialize | ||
if !pointsYielded { | ||
out.max = val | ||
out.min = val | ||
pointsYielded = true | ||
} | ||
out.max = math.Max(out.max, val) | ||
out.min = math.Min(out.min, val) | ||
} | ||
if pointsYielded { | ||
e.Emit(Key{tmax, itr.Tags()}, out) | ||
} | ||
} | ||
|
||
// ReduceSpread computes the spread of values. | ||
func ReduceSpread(key Key, values []interface{}, e *Emitter) { | ||
var result spreadMapOutput | ||
pointsYielded := false | ||
|
||
for _, v := range values { | ||
val := v.(spreadMapOutput) | ||
// Initialize | ||
if !pointsYielded { | ||
result.max = val.max | ||
result.min = val.min | ||
pointsYielded = true | ||
} | ||
result.max = math.Max(result.max, val.max) | ||
result.min = math.Min(result.min, val.min) | ||
} | ||
spread := result.max - result.min | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not much point calculating |
||
if pointsYielded { | ||
e.Emit(key, spread) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense. changed. |
||
} | ||
} | ||
|
||
// MapStddev collects the values to pass to the reducer | ||
func MapStddev(itr Iterator, e *Emitter, tmax int64) { | ||
var values []float64 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2154,10 +2154,11 @@ func (s *Server) executeShowMeasurementsStatement(stmt *influxql.ShowMeasurement | |
row.Values = append(row.Values, []interface{}{v}) | ||
} | ||
|
||
// Make a result. | ||
// Make result. | ||
result := &Result{ | ||
Rows: influxql.Rows{row}, | ||
Rows: make(influxql.Rows, 1), | ||
} | ||
result.Rows[0] = row | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change was due to go vet failing. There is an unfortunate side affect of typed slices outside of the package that it doesn't understand, and will likely not change this behavior. |
||
|
||
return result | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be exported so that they can be serialized later