From 000f6a2e23d29a20a0214dc99aa394876a778b30 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Mon, 15 Apr 2013 11:56:23 +0200 Subject: [PATCH] Allow lower-case BY operator. --- rules/lexer.l | 2 +- rules/lexer.l.go | 2 +- rules/rules_test.go | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/rules/lexer.l b/rules/lexer.l index 4904f7a5b..0424d2e15 100644 --- a/rules/lexer.l +++ b/rules/lexer.l @@ -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 } diff --git a/rules/lexer.l.go b/rules/lexer.l.go index 8f66be610..26907d708 100644 --- a/rules/lexer.l.go +++ b/rules/lexer.l.go @@ -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" { diff --git a/rules/rules_test.go b/rules/rules_test.go index 68a366abe..37e822686 100644 --- a/rules/rules_test.go +++ b/rules/rules_test.go @@ -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, }, {