mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +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
|
containsStar bool
|
||||||
|
|
||||||
phi float64
|
phi float64
|
||||||
|
phiStr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sq *statsQuantile) String() 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) {
|
func (sq *statsQuantile) updateNeededFields(neededFields fieldsSet) {
|
||||||
|
@ -186,12 +187,13 @@ func parseStatsQuantile(lex *lexer) (*statsQuantile, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse phi
|
// Parse phi
|
||||||
phi, ok := tryParseFloat64(fields[0])
|
phiStr := fields[0]
|
||||||
|
phi, ok := tryParseFloat64(phiStr)
|
||||||
if !ok {
|
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 {
|
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
|
// Parse fields
|
||||||
|
@ -205,6 +207,7 @@ func parseStatsQuantile(lex *lexer) (*statsQuantile, error) {
|
||||||
containsStar: slices.Contains(fields, "*"),
|
containsStar: slices.Contains(fields, "*"),
|
||||||
|
|
||||||
phi: phi,
|
phi: phi,
|
||||||
|
phiStr: phiStr,
|
||||||
}
|
}
|
||||||
return sq, nil
|
return sq, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,31 @@ import (
|
||||||
"testing"
|
"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) {
|
func TestHistogramQuantile(t *testing.T) {
|
||||||
f := func(a []float64, phi, qExpected float64) {
|
f := func(a []float64, phi, qExpected float64) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
Loading…
Reference in a new issue