-
Notifications
You must be signed in to change notification settings - Fork 765
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
[sqlparser] better sql parser? #866
Comments
nom-sql |
It seems that sqlparser lacks good alternatives. If necessary, we may need to maintain one by ourselves. quaint is not a parser, but
toydb-parser is the parser for toydb |
How about parsers from yacc rules? |
FYI : lalrpop: an lr(1) parser generator (lexer could be customized) repo: https://github.com/lalrpop/lalrpop
After googling around, I found a SQL parser using it: https://github.com/hmwill/vervolg/blob/main/src/sql.lalrpop |
I think we can fork nom-sql or make one from scratch(not a big deal). Here's a |
https://github.com/lalrpop/lalrpop is rust yacc |
Based on my experience, working with bison(yacc) is suffering. Here's the MySQL's yacc file, which has about 17,000 LOC. https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy Imagine that coding in a extremely huge plain text file without lint tool(no jump, no high light, no auto format), what a pain. |
You are right, I also prefer a handwritten parser |
yes, hard to make changes to it |
If writing your own, maybe something like |
@abhikjain360 Thanks for the information, cool |
Maybe our sql parser is support multi dialect
|
@zhang2014 Maybe we can disscuss this in #1218 |
maybe handwritten parser is a good approach |
Hi! |
As we discussed in #1492 , the main idea about SQL grammar is based on PostgreSQL. Here's a reference of PostgreSQL grammar https://www.postgresql.org/docs/13/sql-select.html. So the last problem is technical selection. |
Nice, @leiysky which one(or list) do you personally preferred? |
I prefer parser combinator like Thanks to its declaritive style, the parser written with parser combinator follows the grammar specification, which means you can add your own syntax element easily(generally you need to modify the grammar specification first to make sure it's well defined). |
|
IMHO, it's because they don't have enough motivation to maintain a SQL parser by themselves. |
Ok, make sense to use nom. |
https://github.com/peterhal/presto_rs/ Hope it helps |
Antlr is a powerful parser framework as well. I didn't involve it since AFAIK currently there is no official rust target. Seems this library has been used by some projects, I'll take a look at it. Thanks very much. |
@leiysky What is the major motivation to replace |
Hi, @hustnn. Actually, we haven't decided which scheme to use yet. We'd like to have a more maintainable SQL, which is easy for us to support new SQL syntax. Do you have any suggestion about this? |
I am implementing a demo to show the possibility of the sql parser on top of nom but I feel the effort is still quite high even it already provides some combinators for usage. The biggest benefit of have a own parser is more flexible like you can define the ASTs structure you want. Also nom did provide some powerful combinators so we can leverage them when building own parser. I feel can try implement own parser based on nom in long term, but I suggest to focus on other high priority tasks first with existing parser. How do you think? @leiysky |
@hustnn Sorry for replying so late.
You actually get the point. We do have a set of AST structure defined by ourselves, with which I'm doing some refactor. These AST structures can be directly transformed from
|
I've recently taken a look at this project. It's in a very early stage, and the author hasn't put much effort into it. Besides, antlr relies on java to run the code generator, which may bring unnecessary complexity for our development workflow. |
I've implemented a simple SQL parser using nom, including complex SELECT(except WINDOW clause) and simple INSERT/DELETE/UPDATE. |
The new parser is now tracking by #1218 |
Summary
sqlparser-rs is not easy to extend and we are looking for a good alternative(if have), comments are welcome
Reference:
https://github.com/datafuselabs/datafuse/blob/36dce2064742a1d64bfcf9a7cd308d0f5a3e4eb5/fusequery/query/src/sql/sql_parser.rs
The text was updated successfully, but these errors were encountered: