mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Save
This commit is contained in:
parent
5bac9fd131
commit
87a576563b
2 changed files with 32 additions and 2 deletions
19
README.md
19
README.md
|
@ -2,6 +2,21 @@
|
|||
|
||||
The goal of this project is to build a SQL lexer and parser capable of parsing ANSI SQL:2011 (or 2016 if I can get access to the specification for free).
|
||||
|
||||
The current code was copied from DataFusion and has some non-standard SQL support and only a subset of ANSI SQL currently.
|
||||
The current code is capable of parsing some simple SELECT and CREATE TABLE statements.
|
||||
|
||||
The current code is capable of parsing some simple SELECT and CREATE TABLE statements.
|
||||
```rust
|
||||
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
|
||||
|
||||
```rust
|
||||
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 }
|
||||
```
|
15
examples/parse_select.rs
Normal file
15
examples/parse_select.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
extern crate sqlparser;
|
||||
|
||||
use sqlparser::sqlparser::*;
|
||||
|
||||
fn main() {
|
||||
|
||||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue