sqlparser: parse empty statements as nil#4084
sqlparser: parse empty statements as nil#4084sougou merged 1 commit intovitessio:masterfrom dt:empty
Conversation
|
Looks like |
|
hm, that test has me thinking that some callers might not like this change -- they might be assuming once they make it though the Maybe it'd be safer to return a non-nil error value instead -- it could always be a sentinel value, so those callers that explicitly want to check for and handle (i.e. ignore) empty statements can still do so, but existing callers wouldn't risk hitting nils. |
|
That's a good point. I'm thinking you can introduce an go/vt/sqlparser/ast.go|51 col 6| references to func Parse(sql string) (Statement, error) |
|
hmm, I gave the sentinel error approach try, so that existing callers that expect an error from an empty statement will still get one and should not change their behavior (beyond the error message) -- I've pushed a revision with that approach, which changes a relatively small number of call sites. What do you think? |
Cases like `/* a comment */; /* another comment */;` end up becoming empty statements after the comments are skipped by the lexer, which then surface as syntax errors. This changes the parser to return a special, sentinel error value for empty statements, so a caller wishing to do so can check for and handle them differently than real syntax errors (e.g. ignore them). Additionally, `ParseNext` can simply skip empty statements directly. Cases like the above appear in the default output of `mysqldump`. Signed-off-by: David Taylor <tinystatemachine@gmail.com>
sougou
left a comment
There was a problem hiding this comment.
I actually looked at the call sites. You would have to change only a few places, that I could easily identify.
But this is good for now because it's a smaller blast radius. I'll think about changing it later if I get back in here.
Cases like
/* a comment */; /* another comment */;end up becomingempty statements after the comments are skipped by the lexer, which then
surface as syntax errors.
This changes the parser to return a nil statement rather than an error.
Cases like this appear in the default output of
mysqldump.