This commit is contained in:
Aliaksandr Valialkin 2024-05-28 17:39:42 +02:00
parent 3fa5ca8a8f
commit a013cb0ca3
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
3 changed files with 9 additions and 14 deletions

View file

@ -1081,6 +1081,10 @@ func TestParseQuerySuccess(t *testing.T) {
f(`foo | # some comment | foo bar f(`foo | # some comment | foo bar
fields x # another comment fields x # another comment
|filter "foo#this#isn't a comment"#this is comment`, `foo | fields x | filter "foo#this#isn't a 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) { func TestParseQueryFailure(t *testing.T) {

View file

@ -149,7 +149,7 @@ func parsePipe(lex *lexer) (pipe, error) {
} }
return pl, nil return pl, nil
case lex.isKeyword("math"): case lex.isKeyword("math"):
pm, err := parsePipeMath(lex, true) pm, err := parsePipeMath(lex)
if err != nil { if err != nil {
return nil, fmt.Errorf("cannot parse 'math' pipe: %w", err) return nil, fmt.Errorf("cannot parse 'math' pipe: %w", err)
} }
@ -223,13 +223,6 @@ func parsePipe(lex *lexer) (pipe, error) {
default: default:
lexState := lex.backupState() 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 // Try parsing stats pipe without 'stats' keyword
ps, err := parsePipeStats(lex, false) ps, err := parsePipeStats(lex, false)
if err == nil { if err == nil {

View file

@ -350,13 +350,11 @@ func (pmp *pipeMathProcessor) flush() error {
return nil return nil
} }
func parsePipeMath(lex *lexer, needMathKeyword bool) (*pipeMath, error) { func parsePipeMath(lex *lexer) (*pipeMath, error) {
if needMathKeyword { if !lex.isKeyword("math") {
if !lex.isKeyword("math") { return nil, fmt.Errorf("unexpected token: %q; want %q", lex.token, "math")
return nil, fmt.Errorf("unexpected token: %q; want %q", lex.token, "math")
}
lex.nextToken()
} }
lex.nextToken()
var mes []*mathEntry var mes []*mathEntry
for { for {