Merge pull request #142 from prometheus/julius-lowercase-by

Allow lower-case BY operator.
This commit is contained in:
Matt T. Proud 2013-04-15 05:13:35 -07:00
commit 167504efd6
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 */ } \/\/[^\r\n]*\n { /* gobble up one-line comments */ }
permanent { return PERMANENT } 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 = yytext; return AGGR_OP }
avg|sum|max|min { yylval.str = strings.ToUpper(yytext); return AGGR_OP } avg|sum|max|min { yylval.str = strings.ToUpper(yytext); return AGGR_OP }
\<|>|AND|OR { yylval.str = yytext; return CMP_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{PERMANENT, yyRT_USER_RETURN}
} }
return yyactionreturn{0, yyRT_FALLTHROUGH} 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() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
if r != "yyREJECT" { if r != "yyREJECT" {

View File

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