From 357caf68c3fbe73ab3a37c1f6a9593a1c22a042e Mon Sep 17 00:00:00 2001 From: Mahesh Arumugam Date: Thu, 24 Jun 2021 15:10:05 -0700 Subject: [PATCH] Fix percentile query: field is mandatory (should not crash), fieldnames can be unquoted --- executor.go | 4 ++-- executor_test.go | 5 +++++ pql/ast.go | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/executor.go b/executor.go index 15d6fb571..449bd69ee 100644 --- a/executor.go +++ b/executor.go @@ -1239,10 +1239,10 @@ func (e *executor) executePercentile(ctx context.Context, qcx *Qcx, index string } // get field - if fieldArg := c.Args["field"]; fieldArg == "" { + fieldName, err := c.FirstStringArg("field", "_field") + if err != nil { return ValCount{}, errors.New("Percentile(): field required") } - fieldName, _, _ := c.StringArg("field") // filter call for min & max var filterCall *pql.Call diff --git a/executor_test.go b/executor_test.go index 9427914b2..856c2b600 100644 --- a/executor_test.go +++ b/executor_test.go @@ -7026,6 +7026,11 @@ func variousQueriesOnPercentiles(t *testing.T, c *test.Cluster) { query: query, csvVerifier: fmt.Sprintf("%d,1\n", expectedPercentile), }) + query2 := fmt.Sprintf(`Percentile(field=net_worth, filter=Row(val="foo"), nth=%d)`, nth) + tests = append(tests, testCase{ + query: query2, + csvVerifier: fmt.Sprintf("%d,1\n", expectedPercentile), + }) } for i, tst := range tests { diff --git a/pql/ast.go b/pql/ast.go index cb1b78b9e..dddf72812 100644 --- a/pql/ast.go +++ b/pql/ast.go @@ -481,6 +481,7 @@ var callInfoByFunc = map[string]callInfo{ allowUnknown: false, prototypes: map[string]interface{}{ "field": "", + "_field": "", "filter": nil, "nth": nil, },