mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 23:49:10 +00:00
Adding rustdoc comments
This commit is contained in:
parent
ecc6b5fb38
commit
9cc4bc3423
2 changed files with 72 additions and 2 deletions
21
src/lib.rs
21
src/lib.rs
|
@ -12,6 +12,27 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
//! SQL Parser for Rust
|
||||||
|
//!
|
||||||
|
//! Example code:
|
||||||
|
//!
|
||||||
|
//! This crate provides an ANSI:SQL 2011 lexer and parser that can parsed SQL into an Abstract
|
||||||
|
//! Syntax Tree (AST).
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//! use sqlparser::sqlparser::Parser;
|
||||||
|
//!
|
||||||
|
//! 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);
|
||||||
|
//! ```
|
||||||
|
|
||||||
|
|
||||||
extern crate fnv;
|
extern crate fnv;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
|
|
@ -17,51 +17,100 @@
|
||||||
/// SQL Abstract Syntax Tree (AST)
|
/// SQL Abstract Syntax Tree (AST)
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum ASTNode {
|
pub enum ASTNode {
|
||||||
|
/// Identifier e.g. table name or column name
|
||||||
SQLIdentifier(String),
|
SQLIdentifier(String),
|
||||||
|
/// Wildcard e.g. `*`
|
||||||
SQLWildcard,
|
SQLWildcard,
|
||||||
|
/// Multi part identifier e.g. `myschema.dbo.mytable`
|
||||||
SQLCompoundIdentifier(Vec<String>),
|
SQLCompoundIdentifier(Vec<String>),
|
||||||
|
/// Assigment e.g. `name = 'Fred'` in an UPDATE statement
|
||||||
|
SQLAssignment(String, Box<ASTNode>),
|
||||||
|
/// `IS NULL` expression
|
||||||
SQLIsNull(Box<ASTNode>),
|
SQLIsNull(Box<ASTNode>),
|
||||||
|
/// `IS NOT NULL` expression
|
||||||
SQLIsNotNull(Box<ASTNode>),
|
SQLIsNotNull(Box<ASTNode>),
|
||||||
|
/// Binary expression e.g. `1 + 1` or `foo > bar`
|
||||||
SQLBinaryExpr {
|
SQLBinaryExpr {
|
||||||
left: Box<ASTNode>,
|
left: Box<ASTNode>,
|
||||||
op: SQLOperator,
|
op: SQLOperator,
|
||||||
right: Box<ASTNode>,
|
right: Box<ASTNode>,
|
||||||
},
|
},
|
||||||
|
/// CAST an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))`
|
||||||
SQLCast {
|
SQLCast {
|
||||||
expr: Box<ASTNode>,
|
expr: Box<ASTNode>,
|
||||||
data_type: SQLType,
|
data_type: SQLType,
|
||||||
},
|
},
|
||||||
|
/// Nested expression e.g. `(foo > bar)` or `(1)`
|
||||||
SQLNested(Box<ASTNode>),
|
SQLNested(Box<ASTNode>),
|
||||||
|
/// Unary expression
|
||||||
SQLUnary {
|
SQLUnary {
|
||||||
operator: SQLOperator,
|
operator: SQLOperator,
|
||||||
rex: Box<ASTNode>,
|
rex: Box<ASTNode>,
|
||||||
},
|
},
|
||||||
|
/// Literal signed long
|
||||||
SQLLiteralLong(i64),
|
SQLLiteralLong(i64),
|
||||||
|
/// Literal floating point value
|
||||||
SQLLiteralDouble(f64),
|
SQLLiteralDouble(f64),
|
||||||
|
/// Literal string
|
||||||
SQLLiteralString(String),
|
SQLLiteralString(String),
|
||||||
|
/// Scalar function call e.g. `LEFT(foo, 5)`
|
||||||
SQLFunction {
|
SQLFunction {
|
||||||
id: String,
|
id: String,
|
||||||
args: Vec<ASTNode>,
|
args: Vec<ASTNode>,
|
||||||
},
|
},
|
||||||
|
/// Expression with ASC/DESC attribute e.g. `foo ASC` or `foo DESC`.=
|
||||||
SQLOrderBy {
|
SQLOrderBy {
|
||||||
expr: Box<ASTNode>,
|
expr: Box<ASTNode>,
|
||||||
asc: bool,
|
asc: bool,
|
||||||
},
|
},
|
||||||
|
/// SELECT
|
||||||
SQLSelect {
|
SQLSelect {
|
||||||
|
/// projection expressions
|
||||||
projection: Vec<ASTNode>,
|
projection: Vec<ASTNode>,
|
||||||
|
/// FROM
|
||||||
relation: Option<Box<ASTNode>>,
|
relation: Option<Box<ASTNode>>,
|
||||||
|
/// WHERE
|
||||||
selection: Option<Box<ASTNode>>,
|
selection: Option<Box<ASTNode>>,
|
||||||
|
/// ORDER BY
|
||||||
order_by: Option<Vec<ASTNode>>,
|
order_by: Option<Vec<ASTNode>>,
|
||||||
|
/// GROUP BY
|
||||||
group_by: Option<Vec<ASTNode>>,
|
group_by: Option<Vec<ASTNode>>,
|
||||||
|
/// HAVING
|
||||||
having: Option<Box<ASTNode>>,
|
having: Option<Box<ASTNode>>,
|
||||||
|
/// LIMIT
|
||||||
limit: Option<Box<ASTNode>>,
|
limit: Option<Box<ASTNode>>,
|
||||||
},
|
},
|
||||||
|
/// INSERT
|
||||||
|
SQLInsert {
|
||||||
|
/// TABLE
|
||||||
|
table_name: String,
|
||||||
|
/// COLUMNS
|
||||||
|
columns: Vec<String>,
|
||||||
|
/// VALUES (vector of rows to insert)
|
||||||
|
values: Vec<Vec<ASTNode>>,
|
||||||
|
},
|
||||||
|
/// UPDATE
|
||||||
|
SQLUpdate {
|
||||||
|
/// TABLE
|
||||||
|
table_name: String,
|
||||||
|
/// Columns being assigned
|
||||||
|
columns: Vec<String>,
|
||||||
|
/// Values being assigned
|
||||||
|
values: Vec<ASTNode>,
|
||||||
|
/// WHERE
|
||||||
|
selection: Option<Box<ASTNode>>,
|
||||||
|
},
|
||||||
|
/// DELETE
|
||||||
SQLDelete {
|
SQLDelete {
|
||||||
relation: Option<Box<ASTNode>>, // FROM statement
|
/// FROM
|
||||||
selection: Option<Box<ASTNode>>, // WHERE statement
|
relation: Option<Box<ASTNode>>,
|
||||||
|
/// WHERE
|
||||||
|
selection: Option<Box<ASTNode>>,
|
||||||
|
/// ORDER BY
|
||||||
order_by: Option<Vec<ASTNode>>,
|
order_by: Option<Vec<ASTNode>>,
|
||||||
limit: Option<Box<ASTNode>>,
|
limit: Option<Box<ASTNode>>,
|
||||||
},
|
},
|
||||||
|
/// CREATE TABLE
|
||||||
SQLCreateTable {
|
SQLCreateTable {
|
||||||
/// Table name
|
/// Table name
|
||||||
name: String,
|
name: String,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue