SSE: Reduce to apply Mode to instant vector (mathexp.Number) (#74859)

This commit is contained in:
Yuri Tseretyan
2023-09-14 12:26:00 -04:00
committed by GitHub
parent fb91919e3b
commit 68eda133e4
2 changed files with 82 additions and 30 deletions

View File

@ -175,12 +175,21 @@ func (gr *ReduceCommand) Execute(ctx context.Context, _ time.Time, vars mathexp.
}
newRes.Values = append(newRes.Values, num)
case mathexp.Number: // if incoming vars is just a number, any reduce op is just a noop, add it as it is
value := v.GetFloat64Value()
if gr.seriesMapper != nil {
value = gr.seriesMapper.MapInput(value)
if value == nil { // same logic as in mapSeries
continue
}
}
copyV := mathexp.NewNumber(gr.refID, v.GetLabels())
copyV.SetValue(v.GetFloat64Value())
copyV.AddNotice(data.Notice{
Severity: data.NoticeSeverityWarning,
Text: fmt.Sprintf("Reduce operation is not needed. Input query or expression %s is already reduced data.", gr.VarToReduce),
})
copyV.SetValue(value)
if gr.seriesMapper == nil {
copyV.AddNotice(data.Notice{
Severity: data.NoticeSeverityWarning,
Text: fmt.Sprintf("Reduce operation is not needed. Input query or expression %s is already reduced data.", gr.VarToReduce),
})
}
newRes.Values = append(newRes.Values, copyV)
case mathexp.NoData:
newRes.Values = append(newRes.Values, v.New())