Skip to content
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

Merged
merged 4 commits into from
Jun 27, 2019
Merged

Conversation

findepi
Copy link
Member

@findepi findepi commented Jun 25, 2019

No description provided.

@findepi findepi requested a review from martint June 25, 2019 21:12
@cla-bot cla-bot bot added the cla-signed label Jun 25, 2019
@@ -182,6 +182,12 @@ public Analyzer(
int tokenIndex = current.tokenIndex;
CallerContext caller = current.caller;

while (tokenIndex < stream.size() && stream.get(tokenIndex).getType() == SqlBaseParser.WS) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • tokenIndex < stream.size() is redundant
  • SqlBaseParser.WS should be provided as configuration

Copy link
Member

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

@findepi findepi force-pushed the error-handler branch 2 times, most recently from cb6af51 to d6bc2ca Compare June 26, 2019 20:33
Copy link
Member

@martint martint left a 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) {
Copy link
Member

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

Copy link
Member Author

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.)

Copy link
Member Author

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.

@findepi findepi force-pushed the error-handler branch 4 times, most recently from 7e470d1 to e450457 Compare June 27, 2019 15:03
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`).
@findepi findepi merged commit 304e8b3 into trinodb:master Jun 27, 2019
@findepi findepi deleted the error-handler branch June 27, 2019 19:59
@findepi findepi mentioned this pull request Jun 27, 2019
6 tasks
@findepi findepi added this to the 316 milestone Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants