-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor cleanup in parsing error handler #1042
Conversation
@@ -182,6 +182,12 @@ public Analyzer( | |||
int tokenIndex = current.tokenIndex; | |||
CallerContext caller = current.caller; | |||
|
|||
while (tokenIndex < stream.size() && stream.get(tokenIndex).getType() == SqlBaseParser.WS) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokenIndex < stream.size()
is redundantSqlBaseParser.WS
should be provided as configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this instead: stream.get(tokenIndex).getChannel() == Token.HIDDEN_CHANNEL
presto-parser/src/main/java/io/prestosql/sql/parser/ErrorHandler.java
Outdated
Show resolved
Hide resolved
cb6af51
to
d6bc2ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but check the potential out-of-bounds condition.
@@ -182,6 +182,12 @@ public Analyzer( | |||
int tokenIndex = current.tokenIndex; | |||
CallerContext caller = current.caller; | |||
|
|||
while (stream.get(tokenIndex).getChannel() == Token.HIDDEN_CHANNEL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will fail if the trailing tokens are all whitespace -- it will run out of bounds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think EOF is always the last token and it's DEFAULT_CHANNEL (not HIDDEN_CHANNEL), so I don't need explicit bound check.
(Previously the code depended on this too, bounds were never checked explicitly.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added one more test case: "CREATE TABLE foo "
(the token stream ends with ...WS, EOF).
btw ANTLR emits only one WS token for all consecutive whitespace, so technically the while
loop is not necessary. I am keeping it to avoid reader's astonishment.
7e470d1
to
e450457
Compare
And remove one duplicate test case.
When parsing fails in some ambiguous place, the `ErrorHandler` is invoked at last certain position, which might be `expression` or `primaryExpression`. By expanding special rules, we may produce more accurate suggestions.
Window frame bound may be a non-literal expression. This is already covered by existing test case (`io.prestosql.tests.AbstractTestWindowQueries#testWindowFrames`).
No description provided.