diff --git a/executor.go b/executor.go index 65fe1b0c7..8a0215c0b 100644 --- a/executor.go +++ b/executor.go @@ -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 diff --git a/executor_test.go b/executor_test.go index 62a2784b1..1d69f5662 100644 --- a/executor_test.go +++ b/executor_test.go @@ -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))