diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index f31d0b2e3..01f89c5fe 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -1081,6 +1081,10 @@ func TestParseQuerySuccess(t *testing.T) { f(`foo | # some comment | foo bar fields x # another comment |filter "foo#this#isn't a comment"#this is comment`, `foo | fields x | filter "foo#this#isn't a comment"`) + + // skip 'stats' and 'filter' prefixes + f(`* | by (host) count() rows | rows:>10`, `* | stats by (host) count(*) as rows | filter rows:>10`) + f(`* | (host) count() rows, count() if (error) errors | rows:>10`, `* | stats by (host) count(*) as rows, count(*) if (error) as errors | filter rows:>10`) } func TestParseQueryFailure(t *testing.T) { diff --git a/lib/logstorage/pipe.go b/lib/logstorage/pipe.go index 167ce2c08..89780da49 100644 --- a/lib/logstorage/pipe.go +++ b/lib/logstorage/pipe.go @@ -149,7 +149,7 @@ func parsePipe(lex *lexer) (pipe, error) { } return pl, nil case lex.isKeyword("math"): - pm, err := parsePipeMath(lex, true) + pm, err := parsePipeMath(lex) if err != nil { return nil, fmt.Errorf("cannot parse 'math' pipe: %w", err) } @@ -223,13 +223,6 @@ func parsePipe(lex *lexer) (pipe, error) { default: lexState := lex.backupState() - // Try parsing math pipe without 'math' keyword - pm, err := parsePipeMath(lex, false) - if err == nil { - return pm, nil - } - lex.restoreState(lexState) - // Try parsing stats pipe without 'stats' keyword ps, err := parsePipeStats(lex, false) if err == nil { diff --git a/lib/logstorage/pipe_math.go b/lib/logstorage/pipe_math.go index 5792a4050..47f7ed73a 100644 --- a/lib/logstorage/pipe_math.go +++ b/lib/logstorage/pipe_math.go @@ -350,13 +350,11 @@ func (pmp *pipeMathProcessor) flush() error { return nil } -func parsePipeMath(lex *lexer, needMathKeyword bool) (*pipeMath, error) { - if needMathKeyword { - if !lex.isKeyword("math") { - return nil, fmt.Errorf("unexpected token: %q; want %q", lex.token, "math") - } - lex.nextToken() +func parsePipeMath(lex *lexer) (*pipeMath, error) { + if !lex.isKeyword("math") { + return nil, fmt.Errorf("unexpected token: %q; want %q", lex.token, "math") } + lex.nextToken() var mes []*mathEntry for {