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
Implment backtrack for parser and add a human-friendly pretty printer for errors #4045
Conversation
Thanks for the contribution! Please review the labels and make any necessary changes. |
1 similar comment
Thanks for the contribution! Please review the labels and make any necessary changes. |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/databend/databend/6HcokCKyMmvT6oGYb7sJ5vXwkH47 [Deployment for e4b83c2 canceled] |
Codecov Report
@@ Coverage Diff @@
## main #4045 +/- ##
======================================
Coverage 57% 57%
======================================
Files 821 824 +3
Lines 43468 43995 +527
======================================
+ Hits 24805 25294 +489
- Misses 18663 18701 +38
Continue to review full report at Codecov.
|
Cool, #4039 merged :) |
@BohuTANG thanks! This is also ready for review. |
---------- AST ------------ | ||
ColumnRef { | ||
database: None, | ||
table: None, | ||
column: Identifier { | ||
name: "a", | ||
quote: None, | ||
}, | ||
} |
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.
IMO, it's better to take normalized AST(i.e. the Debug
string of AST) as output, since structure of AST may change in the future.
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.
It is the debug string of AST.
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.
Oh, my fault. I mean the Display
string, which is normalized SQL string of an AST.
Wait for another reviewer approval |
/lgtm Thank you @andylokandy ! |
CI Passed |
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
Now the SQL parser keeps tracking the grammar path it tried and return the longest possible (but failed) path. Also, a pretty printer is added to render the error path into a human-friendly error report.
For example, parsing the statement
truncate table a
will produce:Changelog
Related Issues
Blocked by #4039
Ref #866
Test Plan
Unit Tests