| tag | d9972b8ddc1c6f2f986e7e650ea1a1fe71d894c6 | |
|---|---|---|
| tagger | Andy Grove <andygrove73@gmail.com> | Sat Sep 08 07:24:40 2018 -0600 |
| object | ed40edd3b04f7bdeaadc68e29601d914b646386f |
(cargo-release) version 0.1.4
| commit | ed40edd3b04f7bdeaadc68e29601d914b646386f | [log] [tgz] |
|---|---|---|
| author | Andy Grove <andygrove73@gmail.com> | Sat Sep 08 07:24:32 2018 -0600 |
| committer | Andy Grove <andygrove73@gmail.com> | Sat Sep 08 07:24:32 2018 -0600 |
| tree | a6accc1f6b93dcc315ea6573c60216df40901c97 | |
| parent | 9cc4bc3423c3a7ac4fdd360b623e4234032b60e9 [diff] |
(cargo-release) version 0.1.4
The primary goal of this project is to build a SQL lexer and parser capable of parsing SQL that conforms with the ANSI SQL:2011 standard.
A secondary goal is to make it easy for others to use this library as a foundation for building custom SQL parsers for vendor-specific dialects.
This parser is currently being used by the DataFusion query engine.
The current code is capable of parsing some trivial SELECT and CREATE TABLE statements.
let sql = "SELECT a, b, 123, myfunc(b) \ FROM table_1 \ WHERE a > b AND b < 100 \ ORDER BY a DESC, b"; let ast = Parser::parse_sql(sql.to_string()).unwrap(); println!("AST: {:?}", ast);
This outputs
AST: SQLSelect { projection: [SQLIdentifier("a"), SQLIdentifier("b"), SQLLiteralLong(123), SQLFunction { id: "myfunc", args: [SQLIdentifier("b")] }], relation: Some(SQLIdentifier("table_1")), selection: Some(SQLBinaryExpr { left: SQLBinaryExpr { left: SQLIdentifier("a"), op: Gt, right: SQLIdentifier("b") }, op: And, right: SQLBinaryExpr { left: SQLIdentifier("b"), op: Lt, right: SQLLiteralLong(100) } }), order_by: Some([SQLOrderBy { expr: SQLIdentifier("a"), asc: false }, SQLOrderBy { expr: SQLIdentifier("b"), asc: true }]), group_by: None, having: None, limit: None }
This parser is implemented using the Pratt Parser design, which is a top-down operator-precedence parser.
I am a fan of this design pattern over parser generators for the following reasons:
This is a work in progress but I started some notes on writing a custom SQL parser.
Contributors are welcome! Please see the current issues and feel free to file more!