VictoriaMetrics/lib/logstorage/stats_median.go

62 lines
1.4 KiB
Go
Raw Normal View History

package logstorage
import (
"unsafe"
)
type statsMedian struct {
2024-05-22 21:01:20 +02:00
fields []string
}
func (sm *statsMedian) String() string {
2024-05-22 21:01:20 +02:00
return "median(" + statsFuncFieldsToString(sm.fields) + ")"
}
2024-05-20 04:08:30 +02:00
func (sm *statsMedian) updateNeededFields(neededFields fieldsSet) {
2024-05-22 21:01:20 +02:00
updateNeededFieldsForStatsFunc(neededFields, sm.fields)
}
func (sm *statsMedian) newStatsProcessor() (statsProcessor, int) {
smp := &statsMedianProcessor{
sqp: &statsQuantileProcessor{
sq: &statsQuantile{
2024-05-22 21:01:20 +02:00
fields: sm.fields,
phi: 0.5,
},
},
}
return smp, int(unsafe.Sizeof(*smp)) + int(unsafe.Sizeof(*smp.sqp)) + int(unsafe.Sizeof(*smp.sqp.sq))
}
type statsMedianProcessor struct {
sqp *statsQuantileProcessor
}
func (smp *statsMedianProcessor) updateStatsForAllRows(br *blockResult) int {
return smp.sqp.updateStatsForAllRows(br)
}
func (smp *statsMedianProcessor) updateStatsForRow(br *blockResult, rowIdx int) int {
return smp.sqp.updateStatsForRow(br, rowIdx)
}
func (smp *statsMedianProcessor) mergeState(sfp statsProcessor) {
src := sfp.(*statsMedianProcessor)
smp.sqp.mergeState(src.sqp)
}
func (smp *statsMedianProcessor) finalizeStats() string {
return smp.sqp.finalizeStats()
}
func parseStatsMedian(lex *lexer) (*statsMedian, error) {
2024-05-22 21:01:20 +02:00
fields, err := parseStatsFuncFields(lex, "median")
if err != nil {
return nil, err
}
sm := &statsMedian{
2024-05-22 21:01:20 +02:00
fields: fields,
}
return sm, nil
}