Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion parser/parser_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,15 @@ func (p *Parser) parseSubExpr(pos Pos, precedence int) (Expr, error) {
// parseInfixLoop folds binary operators into expr while the next operator
// binds tighter than precedence; it stops at once on tokens that are no
// operator at all, such as ',' or ')'.
//
// The guard tests the lookahead token, not just the input offset: isEOF only
// reports that no input text is left to lex, which is already true while the
// final token sits unconsumed in p.current(). Stopping on isEOF alone dropped
// a trailing operator instead of reporting its missing operand, so `SELECT a +`
// left the '+' for the statement parser to reject as unexpected trailing input,
// and `SELECT a GLOBAL` silently read the operator as an implicit alias.
func (p *Parser) parseInfixLoop(expr Expr, precedence int) (Expr, error) {
for !p.lexer.isEOF() {
for !p.lexer.isEOF() || p.current() != nil {
nextPrecedence := p.getNextPrecedence()
if nextPrecedence <= precedence {
return expr, nil
Expand Down
8 changes: 8 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ func TestParser_InvalidSyntax(t *testing.T) {
"ALTER ",
"SELECT*FROM A(0A",
"SET A=",
// An operator as the last token of the input is missing its right
// operand. The infix loop used to stop before it, so the operator
// either reached the statement parser as unexpected trailing input or,
// when it was a keyword, was read as an implicit alias.
"SELECT a +",
"SELECT a GLOBAL",
"SELECT a REGEXP",
"SELECT * FROM t WHERE a AND",
}
for _, sql := range invalidSQLs {
parser := NewParser(sql)
Expand Down
Loading