add new test cases for limits and clarify error messages

This commit is contained in:
Maxton Huff 2021-03-29 16:55:50 -05:00
parent 4c8dc8d54f
commit 13ec97abf5
2 changed files with 7 additions and 4 deletions

View file

@ -1304,7 +1304,10 @@ func (e *executor) executePercentile(ctx context.Context, qcx *Qcx, index string
// get nth
var nthFloat float64
nthArg := c.Args["nth"]
nthArg, ok := c.Args["nth"]
if !ok {
return ValCount{}, errors.New("Percentile(): nth required")
}
if nthArg == nil {
return ValCount{}, errors.New("Percentile(): nth required")
}
@ -1314,10 +1317,10 @@ func (e *executor) executePercentile(ctx context.Context, qcx *Qcx, index string
case int64:
nthFloat = float64(nthArg)
default:
return ValCount{}, errors.Errorf("Percentile(): invalid nth='%v' of type (%[1]T), should be int64 or pql.Decimal", c.Args["nth"])
return ValCount{}, errors.Errorf("Percentile(): invalid nth='%v' of type (%[1]T), should be a number between 0 and 100 inclusive", c.Args["nth"])
}
if nthFloat < 0 || nthFloat > 100.0 {
return ValCount{}, errors.Errorf("Percentile(): invalid nth value (%f), should be between 0 and 100 inclusive", nthFloat)
return ValCount{}, errors.Errorf("Percentile(): invalid nth value (%f), should be a number between 0 and 100 inclusive", nthFloat)
}
// get field

View file

@ -7137,7 +7137,7 @@ func variousQueriesOnPercentiles(t *testing.T, c *test.Cluster) {
csvVerifier: fmt.Sprintf("%d,1\n", expectedPercentile),
})
}
nthsInt := []int64{10}
nthsInt := []int64{0, 10, 100}
for _, nth := range nthsInt {
query := fmt.Sprintf(`Percentile(field="net_worth", filter=Row(val="foo"), nth=%d)`, nth)
expectedPercentile := getExpectedPercentile(nums, float64(nth))