mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-09 23:46:20 +00:00
Rename SQLStatement::SQLSelect to SQLQuery
The name was confusing: SQLStatement::SQLSelect( SQLQuery { body: SQLSetExpr::Select(SQLSelect) } ) Fix the `large_enum_variant` clippy lint for `SQLStatement::SQLQuery` `SQLStatement::SQLCreateView`, and `SQLSetExpr::Select`, while we're changing the AST anyway https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
This commit is contained in:
parent
08bbce8992
commit
50a2310173
5 changed files with 21 additions and 18 deletions
|
@ -202,7 +202,7 @@ impl ToString for ASTNode {
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum SQLStatement {
|
||||
/// SELECT
|
||||
SQLSelect(SQLQuery),
|
||||
SQLQuery(Box<SQLQuery>),
|
||||
/// INSERT
|
||||
SQLInsert {
|
||||
/// TABLE
|
||||
|
@ -240,7 +240,7 @@ pub enum SQLStatement {
|
|||
SQLCreateView {
|
||||
/// View name
|
||||
name: SQLObjectName,
|
||||
query: SQLQuery,
|
||||
query: Box<SQLQuery>,
|
||||
materialized: bool,
|
||||
},
|
||||
/// CREATE TABLE
|
||||
|
@ -264,7 +264,7 @@ pub enum SQLStatement {
|
|||
impl ToString for SQLStatement {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
SQLStatement::SQLSelect(s) => s.to_string(),
|
||||
SQLStatement::SQLQuery(s) => s.to_string(),
|
||||
SQLStatement::SQLInsert {
|
||||
table_name,
|
||||
columns,
|
||||
|
|
|
@ -50,7 +50,7 @@ impl ToString for SQLQuery {
|
|||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum SQLSetExpr {
|
||||
/// Restricted SELECT .. FROM .. HAVING (no ORDER BY or set operations)
|
||||
Select(SQLSelect),
|
||||
Select(Box<SQLSelect>),
|
||||
/// Parenthesized SELECT subquery, which may include more set operations
|
||||
/// in its body and an optional ORDER BY / LIMIT.
|
||||
Query(Box<SQLQuery>),
|
||||
|
|
|
@ -90,7 +90,7 @@ impl Parser {
|
|||
Token::SQLWord(ref w) if w.keyword != "" => match w.keyword.as_ref() {
|
||||
"SELECT" | "WITH" => {
|
||||
self.prev_token();
|
||||
Ok(SQLStatement::SQLSelect(self.parse_query()?))
|
||||
Ok(SQLStatement::SQLQuery(Box::new(self.parse_query()?)))
|
||||
}
|
||||
"CREATE" => Ok(self.parse_create()?),
|
||||
"DELETE" => Ok(self.parse_delete()?),
|
||||
|
@ -655,7 +655,7 @@ impl Parser {
|
|||
// Some dialects allow WITH here, followed by some keywords (e.g. MS SQL)
|
||||
// or `(k1=v1, k2=v2, ...)` (Postgres)
|
||||
self.expect_keyword("AS")?;
|
||||
let query = self.parse_query()?;
|
||||
let query = Box::new(self.parse_query()?);
|
||||
// Optional `WITH [ CASCADED | LOCAL ] CHECK OPTION` is widely supported here.
|
||||
Ok(SQLStatement::SQLCreateView {
|
||||
name,
|
||||
|
@ -1266,7 +1266,7 @@ impl Parser {
|
|||
// We parse the expression using a Pratt parser, as in `parse_expr()`.
|
||||
// Start by parsing a restricted SELECT or a `(subquery)`:
|
||||
let mut expr = if self.parse_keyword("SELECT") {
|
||||
SQLSetExpr::Select(self.parse_select()?)
|
||||
SQLSetExpr::Select(Box::new(self.parse_select()?))
|
||||
} else if self.consume_token(&Token::LParen) {
|
||||
// CTEs are not allowed here, but the parser currently accepts them
|
||||
let subquery = self.parse_query()?;
|
||||
|
|
|
@ -5,15 +5,18 @@ use sqlparser::sqlparser::*;
|
|||
#[test]
|
||||
fn parse_simple_select() {
|
||||
let sql = String::from("SELECT id, fname, lname FROM customer WHERE id = 1");
|
||||
let ast = Parser::parse_sql(&AnsiSqlDialect {}, sql).unwrap();
|
||||
let mut ast = Parser::parse_sql(&AnsiSqlDialect {}, sql).unwrap();
|
||||
assert_eq!(1, ast.len());
|
||||
match ast.first().unwrap() {
|
||||
SQLStatement::SQLSelect(SQLQuery {
|
||||
body: SQLSetExpr::Select(SQLSelect { projection, .. }),
|
||||
match ast.pop().unwrap() {
|
||||
SQLStatement::SQLQuery(q) => match *q {
|
||||
SQLQuery {
|
||||
body: SQLSetExpr::Select(select),
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(3, projection.len());
|
||||
} => {
|
||||
assert_eq!(3, select.projection.len());
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1003,8 +1003,8 @@ fn only<T>(v: &[T]) -> &T {
|
|||
|
||||
fn verified_query(query: &str) -> SQLQuery {
|
||||
match verified_stmt(query) {
|
||||
SQLStatement::SQLSelect(select) => select,
|
||||
_ => panic!("Expected SELECT"),
|
||||
SQLStatement::SQLQuery(query) => *query,
|
||||
_ => panic!("Expected SQLQuery"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1017,7 +1017,7 @@ fn expr_from_projection(item: &SQLSelectItem) -> &ASTNode {
|
|||
|
||||
fn verified_only_select(query: &str) -> SQLSelect {
|
||||
match verified_query(query).body {
|
||||
SQLSetExpr::Select(s) => s,
|
||||
SQLSetExpr::Select(s) => *s,
|
||||
_ => panic!("Expected SQLSetExpr::Select"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue