Allow lower-case BY operator.

This commit is contained in:
Julius Volz 2013-04-15 11:56:23 +02:00
parent f21b5ad12b
commit 000f6a2e23
3 changed files with 7 additions and 4 deletions

View file

@ -38,7 +38,7 @@ U [smhdwy]
\/\/[^\r\n]*\n { /* gobble up one-line comments */ }
permanent { return PERMANENT }
BY { return GROUP_OP }
BY|by { return GROUP_OP }
AVG|SUM|MAX|MIN { yylval.str = yytext; return AGGR_OP }
avg|sum|max|min { yylval.str = strings.ToUpper(yytext); return AGGR_OP }
\<|>|AND|OR { yylval.str = yytext; return CMP_OP }

View file

@ -315,7 +315,7 @@ var yyrules []yyrule = []yyrule{{regexp.MustCompile("[^\\n]"), nil, []yystartcon
return yyactionreturn{PERMANENT, yyRT_USER_RETURN}
}
return yyactionreturn{0, yyRT_FALLTHROUGH}
}}, {regexp.MustCompile("BY"), nil, []yystartcondition{}, false, func() (yyar yyactionreturn) {
}}, {regexp.MustCompile("BY|by"), nil, []yystartcondition{}, false, func() (yyar yyactionreturn) {
defer func() {
if r := recover(); r != nil {
if r != "yyREJECT" {

View file

@ -219,8 +219,11 @@ var expressionTests = []struct {
intervalRanges: 1,
}, {
// Lower-cased aggregation operators should work too.
expr: "sum(http_requests) + min(http_requests) + max(http_requests) + avg(http_requests)",
output: []string{"http_requests{} => 4950 @[%v]"},
expr: "sum(http_requests) by (job) + min(http_requests) by (job) + max(http_requests) by (job) + avg(http_requests) by (job)",
output: []string{
"http_requests{job='app-server'} => 4550 @[%v]",
"http_requests{job='api-server'} => 1750 @[%v]",
},
fullRanges: 0,
intervalRanges: 8,
}, {