2024-05-15 02:55:44 +00:00
|
|
|
package logstorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
type statsMedian struct {
|
2024-05-22 19:01:20 +00:00
|
|
|
fields []string
|
2024-05-15 02:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sm *statsMedian) String() string {
|
2024-05-22 19:01:20 +00:00
|
|
|
return "median(" + statsFuncFieldsToString(sm.fields) + ")"
|
2024-05-15 02:55:44 +00:00
|
|
|
}
|
|
|
|
|
2024-05-20 02:08:30 +00:00
|
|
|
func (sm *statsMedian) updateNeededFields(neededFields fieldsSet) {
|
2024-05-22 19:01:20 +00:00
|
|
|
updateNeededFieldsForStatsFunc(neededFields, sm.fields)
|
2024-05-15 02:55:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sm *statsMedian) newStatsProcessor() (statsProcessor, int) {
|
|
|
|
smp := &statsMedianProcessor{
|
|
|
|
sqp: &statsQuantileProcessor{
|
|
|
|
sq: &statsQuantile{
|
2024-05-22 19:01:20 +00:00
|
|
|
fields: sm.fields,
|
|
|
|
phi: 0.5,
|
2024-05-15 02:55:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
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 19:01:20 +00:00
|
|
|
fields, err := parseStatsFuncFields(lex, "median")
|
2024-05-15 02:55:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
sm := &statsMedian{
|
2024-05-22 19:01:20 +00:00
|
|
|
fields: fields,
|
2024-05-15 02:55:44 +00:00
|
|
|
}
|
|
|
|
return sm, nil
|
|
|
|
}
|