From 1e4cc12bd07638550fc4dceb064526fe2288b29a Mon Sep 17 00:00:00 2001 From: Matt Jaffee Date: Tue, 2 Mar 2021 21:47:27 -0600 Subject: [PATCH] handle 0th percentile properly --- executor.go | 4 ++++ executor_test.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/executor.go b/executor.go index a0e92ea4b..5025c01a2 100644 --- a/executor.go +++ b/executor.go @@ -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 diff --git a/executor_test.go b/executor_test.go index 7712c4095..63b015816 100644 --- a/executor_test.go +++ b/executor_test.go @@ -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)