handle 0th percentile properly

This commit is contained in:
Matt Jaffee 2021-03-02 21:47:27 -06:00
parent b1f9e6ad05
commit 1e4cc12bd0
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 8 additions and 1 deletions

View file

@ -1361,6 +1361,10 @@ func (e *executor) executePercentile(ctx context.Context, qcx *Qcx, index string
rangeCall = intersectCall.Children[0]
}
if nth == 0.0 {
return ValCount{Val: minVal.Val, Count: minVal.Count}, nil
}
k := (1 - nth) / nth
min, max := minVal.Val, maxVal.Val

View file

@ -6916,6 +6916,9 @@ func variousQueriesOnPercentiles(t *testing.T, c *test.Cluster) {
max = num
}
}
if nth == 0.0 {
return min
}
k := (1 - nth) / nth
possibleNthVal := int64(0)
@ -6990,7 +6993,7 @@ func variousQueriesOnPercentiles(t *testing.T, c *test.Cluster) {
}
// generate test cases per each nth argument
nths := []float64{0.1, 0.25, 0.5, 0.75, 0.9, 0.99}
nths := []float64{0.0, 0.1, 0.25, 0.5, 0.75, 0.9, 0.99}
var tests []testCase
for _, nth := range nths {
query := fmt.Sprintf(`Percentile(field="net_worth", filter=Row(val="foo"), nth=%f)`, nth)