diff --git a/influxql/functions.go b/influxql/functions.go index eff918534ee..ef9704c33e3 100644 --- a/influxql/functions.go +++ b/influxql/functions.go @@ -107,6 +107,10 @@ func InitializeReduceFunc(c *Call) (ReduceFunc, error) { case "last": return ReduceLast, nil case "percentile": + if len(c.Args) != 2 { + return nil, fmt.Errorf("expected float argument in percentile()") + } + lit, ok := c.Args[1].(*NumberLiteral) if !ok { return nil, fmt.Errorf("expected float argument in percentile()") diff --git a/influxql/functions_test.go b/influxql/functions_test.go index 2dfaa11ffe9..1f965e256f4 100644 --- a/influxql/functions_test.go +++ b/influxql/functions_test.go @@ -65,3 +65,36 @@ func TestMapMean(t *testing.T) { } } + +func TestInitializeReduceFuncPercentile(t *testing.T) { + // No args + c := &Call{ + Name: "percentile", + Args: []Expr{}, + } + _, err := InitializeReduceFunc(c) + if err == nil { + t.Errorf("InitializedReduceFunc(%v) expected error. got nil", c) + } + + if exp := "expected float argument in percentile()"; err.Error() != exp { + t.Errorf("InitializedReduceFunc(%v) mismatch. exp %v got %v", c, exp, err.Error()) + } + + // No percentile arg + c = &Call{ + Name: "percentile", + Args: []Expr{ + &VarRef{Val: "field1"}, + }, + } + + _, err = InitializeReduceFunc(c) + if err == nil { + t.Errorf("InitializedReduceFunc(%v) expected error. got nil", c) + } + + if exp := "expected float argument in percentile()"; err.Error() != exp { + t.Errorf("InitializedReduceFunc(%v) mismatch. exp %v got %v", c, exp, err.Error()) + } +}