Update comments after the renaming done in PR #105

This commit is contained in:
Nickolay Ponomarev 2019-07-01 04:45:08 +03:00
parent cdba43682f
commit 7d4b488336
8 changed files with 26 additions and 26 deletions

View file

@ -20,9 +20,9 @@ let sql = "SELECT a, b, 123, myfunc(b) \
WHERE a > b AND b < 100 \
ORDER BY a DESC, b";
let dialect = GenericSqlDialect{}; // or AnsiSqlDialect, or your own dialect ...
let dialect = GenericDialect {}; // or AnsiDialect, or your own dialect ...
let ast = Parser::parse_sql(&dialect,sql.to_string()).unwrap();
let ast = Parser::parse_sql(&dialect, sql.to_string()).unwrap();
println!("AST: {:?}", ast);
```
@ -30,7 +30,7 @@ println!("AST: {:?}", ast);
This outputs
```rust
AST: [SQLSelect(SQLQuery { ctes: [], body: Select(SQLSelect { distinct: false, projection: [UnnamedExpression(SQLIdentifier("a")), UnnamedExpression(SQLIdentifier("b")), UnnamedExpression(SQLValue(Long(123))), UnnamedExpression(SQLFunction { name: SQLObjectName(["myfunc"]), args: [SQLIdentifier("b")], over: None })], relation: Some(Table { name: SQLObjectName(["table_1"]), alias: None }), joins: [], selection: Some(SQLBinaryExpr { left: SQLBinaryExpr { left: SQLIdentifier("a"), op: Gt, right: SQLIdentifier("b") }, op: And, right: SQLBinaryExpr { left: SQLIdentifier("b"), op: Lt, right: SQLValue(Long(100)) } }), group_by: None, having: None }), order_by: Some([SQLOrderByExpr { expr: SQLIdentifier("a"), asc: Some(false) }, SQLOrderByExpr { expr: SQLIdentifier("b"), asc: None }]), limit: None })]
AST: [Query(Query { ctes: [], body: Select(Select { distinct: false, projection: [UnnamedExpr(Identifier("a")), UnnamedExpr(Identifier("b")), UnnamedExpr(Value(Long(123))), UnnamedExpr(Function(Function { name: ObjectName(["myfunc"]), args: [Identifier("b")], over: None, distinct: false }))], from: [TableWithJoins { relation: Table { name: ObjectName(["table_1"]), alias: None, args: [], with_hints: [] }, joins: [] }], selection: Some(BinaryOp { left: BinaryOp { left: Identifier("a"), op: Gt, right: Identifier("b") }, op: And, right: BinaryOp { left: Identifier("b"), op: Lt, right: Value(Long(100)) } }), group_by: [], having: None }), order_by: [OrderByExpr { expr: Identifier("a"), asc: Some(false) }, OrderByExpr { expr: Identifier("b"), asc: None }], limit: None, offset: None, fetch: None })]
```
## Design

View file

@ -1,8 +1,8 @@
//! AST types specific to CREATE/ALTER variants of `SQLStatement`
//! AST types specific to CREATE/ALTER variants of [Statement]
//! (commonly referred to as Data Definition Language, or DDL)
use super::{DataType, Expr, Ident, ObjectName};
/// An `ALTER TABLE` (`SQLStatement::SQLAlterTable`) operation
/// An `ALTER TABLE` (`Statement::AlterTable`) operation
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AlterTableOperation {
/// `ADD <table_constraint>`

View file

@ -57,14 +57,14 @@ pub enum Expr {
/// Identifier e.g. table name or column name
Identifier(Ident),
/// Unqualified wildcard (`*`). SQL allows this in limited contexts, such as:
/// - right after `SELECT` (which is represented as a [SQLSelectItem::Wildcard] instead)
/// - right after `SELECT` (which is represented as a [SelectItem::Wildcard] instead)
/// - or as part of an aggregate function, e.g. `COUNT(*)`,
///
/// ...but we currently also accept it in contexts where it doesn't make
/// sense, such as `* + *`
Wildcard,
/// Qualified wildcard, e.g. `alias.*` or `schema.table.*`.
/// (Same caveats apply to SQLQualifiedWildcard as to SQLWildcard.)
/// (Same caveats apply to `QualifiedWildcard` as to `Wildcard`.)
QualifiedWildcard(Vec<Ident>),
/// Multi-part identifier, e.g. `table_alias.column` or `schema.table.col`
CompoundIdentifier(Vec<Ident>),
@ -115,7 +115,7 @@ pub enum Expr {
},
/// Nested expression e.g. `(foo > bar)` or `(1)`
Nested(Box<Expr>),
/// SQLValue
/// A literal value, such as string, number, date or NULL
Value(Value),
/// Scalar function call e.g. `LEFT(foo, 5)`
Function(Function),
@ -320,12 +320,12 @@ impl FromStr for WindowFrameUnits {
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WindowFrameBound {
/// "CURRENT ROW"
/// `CURRENT ROW`
CurrentRow,
/// "<N> PRECEDING" or "UNBOUNDED PRECEDING"
/// `<N> PRECEDING` or `UNBOUNDED PRECEDING`
Preceding(Option<u64>),
/// "<N> FOLLOWING" or "UNBOUNDED FOLLOWING". This can only appear in
/// SQLWindowFrame::end_bound.
/// `<N> FOLLOWING` or `UNBOUNDED FOLLOWING`. This can only appear in
/// [WindowFrame::end_bound].
Following(Option<u64>),
}
@ -610,7 +610,7 @@ impl ToString for Assignment {
}
}
/// SQL function
/// A function call
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Function {
pub name: ObjectName,

View file

@ -12,7 +12,7 @@
///! This module defines
/// 1) a list of constants for every keyword that
/// can appear in SQLWord::keyword:
/// can appear in [Word::keyword]:
/// pub const KEYWORD = "KEYWORD"
/// 2) an `ALL_KEYWORDS` array with every keyword in it
/// This is not a list of *reserved* keywords: some of these can be

View file

@ -28,7 +28,7 @@ pub trait Dialect: Debug {
/// implementation, accepting "double quoted" ids is both ANSI-compliant
/// and appropriate for most dialects (with the notable exception of
/// MySQL, MS SQL, and sqlite). You can accept one of characters listed
/// in `SQLWord::matching_end_quote()` here
/// in `Word::matching_end_quote` here
fn is_delimited_identifier_start(&self, ch: char) -> bool {
ch == '"'
}

View file

@ -14,14 +14,14 @@
//!
//! Example code:
//!
//! This crate provides an ANSI:SQL 2011 lexer and parser that can parsed SQL into an Abstract
//! Syntax Tree (AST).
//! This crate provides an ANSI:SQL 2011 lexer and parser that can parse SQL
//! into an Abstract Syntax Tree (AST).
//!
//! ```
//! use sqlparser::dialect::GenericDialect;
//! use sqlparser::parser::Parser;
//!
//! let dialect = GenericDialect {}; // or AnsiSqlDialect
//! let dialect = GenericDialect {}; // or AnsiDialect
//!
//! let sql = "SELECT a, b, 123, myfunc(b) \
//! FROM table_1 \

View file

@ -225,7 +225,7 @@ impl Parser {
}
_ => Ok(Expr::Identifier(w.as_ident())),
},
}, // End of Token::SQLWord
}, // End of Token::Word
Token::Mult => Ok(Expr::Wildcard),
tok @ Token::Minus | tok @ Token::Plus => {
let op = if tok == Token::Plus {
@ -1697,7 +1697,7 @@ impl Parser {
// ^ ^ ^ ^
// | | | |
// | | | |
// | | | (4) belongs to a SQLSetExpr::Query inside the subquery
// | | | (4) belongs to a SetExpr::Query inside the subquery
// | | (3) starts a derived table (subquery)
// | (2) starts a nested join
// (1) an additional set of parens around a nested join
@ -1882,7 +1882,7 @@ impl Parser {
Ok(projections)
}
/// Parse a comma-delimited list of SQL ORDER BY expressions
/// Parse a comma-delimited list of ORDER BY expressions
pub fn parse_order_by_expr_list(&mut self) -> Result<Vec<OrderByExpr>, ParserError> {
let mut expr_list: Vec<OrderByExpr> = vec![];
loop {

View file

@ -77,27 +77,27 @@ impl TestedDialects {
only_statement
}
/// Ensures that `sql` parses as a single SQLStatement, and is not modified
/// Ensures that `sql` parses as a single [Statement], and is not modified
/// after a serialization round-trip.
pub fn verified_stmt(&self, query: &str) -> Statement {
self.one_statement_parses_to(query, query)
}
/// Ensures that `sql` parses as a single SQLQuery, and is not modified
/// Ensures that `sql` parses as a single [Query], and is not modified
/// after a serialization round-trip.
pub fn verified_query(&self, sql: &str) -> Query {
match self.verified_stmt(sql) {
Statement::Query(query) => *query,
_ => panic!("Expected SQLQuery"),
_ => panic!("Expected Query"),
}
}
/// Ensures that `sql` parses as a single SQLSelect, and is not modified
/// Ensures that `sql` parses as a single [Select], and is not modified
/// after a serialization round-trip.
pub fn verified_only_select(&self, query: &str) -> Select {
match self.verified_query(query).body {
SetExpr::Select(s) => *s,
_ => panic!("Expected SQLSetExpr::Select"),
_ => panic!("Expected SetExpr::Select"),
}
}