mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 15:16:42 +00:00
wip
This commit is contained in:
parent
d272c4822b
commit
5cb0390dcd
2 changed files with 32 additions and 4 deletions
|
@ -18,10 +18,11 @@ type statsQuantile struct {
|
|||
containsStar bool
|
||||
|
||||
phi float64
|
||||
phiStr string
|
||||
}
|
||||
|
||||
func (sq *statsQuantile) String() string {
|
||||
return fmt.Sprintf("quantile(%g, %s)", sq.phi, fieldNamesString(sq.fields))
|
||||
return fmt.Sprintf("quantile(%s, %s)", sq.phiStr, fieldNamesString(sq.fields))
|
||||
}
|
||||
|
||||
func (sq *statsQuantile) updateNeededFields(neededFields fieldsSet) {
|
||||
|
@ -186,12 +187,13 @@ func parseStatsQuantile(lex *lexer) (*statsQuantile, error) {
|
|||
}
|
||||
|
||||
// Parse phi
|
||||
phi, ok := tryParseFloat64(fields[0])
|
||||
phiStr := fields[0]
|
||||
phi, ok := tryParseFloat64(phiStr)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("phi arg in 'quantile' must be floating point number; got %q", fields[0])
|
||||
return nil, fmt.Errorf("phi arg in 'quantile' must be floating point number; got %q", phiStr)
|
||||
}
|
||||
if phi < 0 || phi > 1 {
|
||||
return nil, fmt.Errorf("phi arg in 'quantile' must be in the range [0..1]; got %q", fields[0])
|
||||
return nil, fmt.Errorf("phi arg in 'quantile' must be in the range [0..1]; got %q", phiStr)
|
||||
}
|
||||
|
||||
// Parse fields
|
||||
|
@ -205,6 +207,7 @@ func parseStatsQuantile(lex *lexer) (*statsQuantile, error) {
|
|||
containsStar: slices.Contains(fields, "*"),
|
||||
|
||||
phi: phi,
|
||||
phiStr: phiStr,
|
||||
}
|
||||
return sq, nil
|
||||
}
|
||||
|
|
|
@ -5,6 +5,31 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestParseStatsQuantileSuccess(t *testing.T) {
|
||||
f := func(pipeStr string) {
|
||||
t.Helper()
|
||||
expectParseStatsFuncSuccess(t, pipeStr)
|
||||
}
|
||||
|
||||
f(`quantile(0.3, *)`)
|
||||
f(`quantile(1, a)`)
|
||||
f(`quantile(0.99, a, b)`)
|
||||
}
|
||||
|
||||
func TestParseStatsQuantileFailure(t *testing.T) {
|
||||
f := func(pipeStr string) {
|
||||
t.Helper()
|
||||
expectParseStatsFuncFailure(t, pipeStr)
|
||||
}
|
||||
|
||||
f(`quantile`)
|
||||
f(`quantile(a)`)
|
||||
f(`quantile(a, b)`)
|
||||
f(`quantile(10, b)`)
|
||||
f(`quantile(-1, b)`)
|
||||
f(`quantile(0.5, b) c`)
|
||||
}
|
||||
|
||||
func TestHistogramQuantile(t *testing.T) {
|
||||
f := func(a []float64, phi, qExpected float64) {
|
||||
t.Helper()
|
||||
|
|
Loading…
Reference in a new issue