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

feat(parser): fix token location and print sql with cursor on parse error #16959

Merged
merged 10 commits into from
May 29, 2024

Conversation

wangrunji0408
Copy link
Contributor

@wangrunji0408 wangrunji0408 commented May 28, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Currently, the location associated with each token is inferred from token length and is not accurate. This PR fixes this problem by inferring location from lower-level chars.

Additionally, this PR appends SQL context to the parse error message.

$ selet 1;
sql parser error: expected an SQL statement, found: selet at line 1, column 1
LINE 1: selet 1;
             ^

Note that the cursor is still not accurate. It may be offset one token forward because the error token has been consumed.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

The error messages of parser have improved. It now prints the SQL context around the error, helping users quickly locate issues.

Signed-off-by: Runji Wang <wangrunji0408@163.com>
@github-actions github-actions bot added the type/fix Bug fix label May 28, 2024
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 changed the title fix(parser): fix location in tokenizer feat(parser): fix token location and print sql with cursor on parse error May 28, 2024
@github-actions github-actions bot added type/feature and removed type/fix Bug fix labels May 28, 2024
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 force-pushed the wrj/fix-tokenizer-loc branch from 85136f0 to c07550a Compare May 28, 2024 07:20
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 force-pushed the wrj/fix-tokenizer-loc branch from 7cb9755 to 1260bf9 Compare May 28, 2024 08:49
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
Signed-off-by: Runji Wang <wangrunji0408@163.com>
@wangrunji0408 wangrunji0408 added the user-facing-changes Contains changes that are visible to users label May 29, 2024
@wangrunji0408 wangrunji0408 enabled auto-merge May 29, 2024 11:16
@wangrunji0408 wangrunji0408 added this pull request to the merge queue May 29, 2024
Merged via the queue into main with commit 2016c32 May 29, 2024
36 of 37 checks passed
@wangrunji0408 wangrunji0408 deleted the wrj/fix-tokenizer-loc branch May 29, 2024 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature user-facing-changes Contains changes that are visible to users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants