Merge pull request #6004 from influxdata/js-5728-improper-semicolon-handling
Properly handle semi-colons as part of the main query looppull/6065/head
commit
cabcf4f2ae
|
@ -12,6 +12,7 @@
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- [#5152](https://github.com/influxdata/influxdb/issues/5152): Fix where filters when a tag and a filter are combined with OR.
|
- [#5152](https://github.com/influxdata/influxdb/issues/5152): Fix where filters when a tag and a filter are combined with OR.
|
||||||
|
- [#5728](https://github.com/influxdata/influxdb/issues/5728): Properly handle semi-colons as part of the main query loop.
|
||||||
|
|
||||||
## v0.11.0 [unreleased]
|
## v0.11.0 [unreleased]
|
||||||
|
|
||||||
|
|
|
@ -63,14 +63,17 @@ func MustParseExpr(s string) Expr {
|
||||||
// ParseQuery parses an InfluxQL string and returns a Query AST object.
|
// ParseQuery parses an InfluxQL string and returns a Query AST object.
|
||||||
func (p *Parser) ParseQuery() (*Query, error) {
|
func (p *Parser) ParseQuery() (*Query, error) {
|
||||||
var statements Statements
|
var statements Statements
|
||||||
var semi bool
|
semi := true
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if tok, _, _ := p.scanIgnoreWhitespace(); tok == EOF {
|
if tok, pos, lit := p.scanIgnoreWhitespace(); tok == EOF {
|
||||||
return &Query{Statements: statements}, nil
|
return &Query{Statements: statements}, nil
|
||||||
} else if !semi && tok == SEMICOLON {
|
} else if tok == SEMICOLON {
|
||||||
semi = true
|
semi = true
|
||||||
} else {
|
} else {
|
||||||
|
if !semi {
|
||||||
|
return nil, newParseError(tokstr(tok, lit), []string{";"}, pos)
|
||||||
|
}
|
||||||
p.unscan()
|
p.unscan()
|
||||||
s, err := p.ParseStatement()
|
s, err := p.ParseStatement()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -51,6 +51,13 @@ func TestParser_ParseQuery_ParseError(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParser_ParseQuery_NoSemicolon(t *testing.T) {
|
||||||
|
_, err := influxql.NewParser(strings.NewReader(`CREATE DATABASE foo CREATE DATABASE bar`)).ParseQuery()
|
||||||
|
if err == nil || err.Error() != `found CREATE, expected ; at line 1, char 21` {
|
||||||
|
t.Fatalf("unexpected error: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the parser can parse strings into Statement ASTs.
|
// Ensure the parser can parse strings into Statement ASTs.
|
||||||
func TestParser_ParseStatement(t *testing.T) {
|
func TestParser_ParseStatement(t *testing.T) {
|
||||||
// For use in various tests.
|
// For use in various tests.
|
||||||
|
|
Loading…
Reference in New Issue