Add type check on topk/bottomk parameter.
This commit is contained in:
parent
fa9cc15573
commit
7f23a4a099
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue