fix(parser): parenthesis around aggregate expression parsing
The position range of nested aggregate expression was wrong, for the
expression "(sum(foo))" the position of "sum(foo)" should be 1-9, but
the parser could not decide the end of the expression on pos 9, instead
it read ahead to pos 10 and then emitted the aggregate. But we only
kept the last closing position (10) and wrote that into the aggregate.
The reason for this is that the parser cannot know from "(sum(foo)" alone
if the aggregate is finished. It could be finished as in "(sum(foo))" but
equally it could continue with group modifier as "(sum(foo) by (bar))".
The fix is to track ")" tokens in a stack in addition to the lastClosing
position, which is overloaded with other things like offset number tracking.
Signed-off-by:
György Krajcsovits <gyorgy.krajcsovits@grafana.com>
Showing
- promql/parser/generated_parser.y 22 additions, 4 deletionspromql/parser/generated_parser.y
- promql/parser/generated_parser.y.go 13 additions, 1 deletionpromql/parser/generated_parser.y.go
- promql/parser/parse.go 19 additions, 2 deletionspromql/parser/parse.go
- promql/parser/parse_test.go 43 additions, 0 deletionspromql/parser/parse_test.go
Please register or sign in to comment