Add type check on topk/bottomk parameter.

This commit is contained in:
Brian Brazil 2016-07-04 18:03:05 +01:00
parent fa9cc15573
commit 7f23a4a099
2 changed files with 7 additions and 0 deletions

View File

@ -1049,6 +1049,9 @@ func (p *parser) checkType(node Node) (typ model.ValueType) {
p.errorf("aggregation operator expected in aggregation expression but got %q", n.Op)
}
p.expectType(n.Expr, model.ValVector, "aggregation expression")
if n.Op == itemTopK || n.Op == itemBottomK {
p.expectType(n.Param, model.ValScalar, "aggregation parameter")
}
case *BinaryExpr:
lt := p.checkType(n.LHS)

View File

@ -1253,6 +1253,10 @@ var testExpr = []struct {
input: `topk(some_metric)`,
fail: true,
errMsg: "parse error at char 17: unexpected \")\" in aggregation, expected \",\"",
}, {
input: `topk(some_metric, other_metric)`,
fail: true,
errMsg: "parse error at char 32: expected type scalar in aggregation parameter, got vector",
},
// Test function calls.
{