mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 18:57:21 +00:00
Don't Box<ASTNode> in SQLSelect
Instead change ASTNode::SQLSubquery to be Box<SQLSelect>
This commit is contained in:
parent
c5bbfc33fd
commit
e3b981a0e2
4 changed files with 17 additions and 17 deletions
|
@ -76,7 +76,7 @@ pub enum ASTNode {
|
||||||
},
|
},
|
||||||
/// A parenthesized subquery `(SELECT ...)`, used in expression like
|
/// A parenthesized subquery `(SELECT ...)`, used in expression like
|
||||||
/// `SELECT (subquery) AS x` or `WHERE (subquery) = x`
|
/// `SELECT (subquery) AS x` or `WHERE (subquery) = x`
|
||||||
SQLSubquery(SQLSelect),
|
SQLSubquery(Box<SQLSelect>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for ASTNode {
|
impl ToString for ASTNode {
|
||||||
|
|
|
@ -6,18 +6,18 @@ pub struct SQLSelect {
|
||||||
pub projection: Vec<ASTNode>,
|
pub projection: Vec<ASTNode>,
|
||||||
/// FROM
|
/// FROM
|
||||||
pub relation: Option<TableFactor>,
|
pub relation: Option<TableFactor>,
|
||||||
// JOIN
|
/// JOIN
|
||||||
pub joins: Vec<Join>,
|
pub joins: Vec<Join>,
|
||||||
/// WHERE
|
/// WHERE
|
||||||
pub selection: Option<Box<ASTNode>>,
|
pub selection: Option<ASTNode>,
|
||||||
/// ORDER BY
|
/// ORDER BY
|
||||||
pub order_by: Option<Vec<SQLOrderByExpr>>,
|
pub order_by: Option<Vec<SQLOrderByExpr>>,
|
||||||
/// GROUP BY
|
/// GROUP BY
|
||||||
pub group_by: Option<Vec<ASTNode>>,
|
pub group_by: Option<Vec<ASTNode>>,
|
||||||
/// HAVING
|
/// HAVING
|
||||||
pub having: Option<Box<ASTNode>>,
|
pub having: Option<ASTNode>,
|
||||||
/// LIMIT
|
/// LIMIT
|
||||||
pub limit: Option<Box<ASTNode>>,
|
pub limit: Option<ASTNode>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToString for SQLSelect {
|
impl ToString for SQLSelect {
|
||||||
|
@ -37,7 +37,7 @@ impl ToString for SQLSelect {
|
||||||
s += &join.to_string();
|
s += &join.to_string();
|
||||||
}
|
}
|
||||||
if let Some(ref selection) = self.selection {
|
if let Some(ref selection) = self.selection {
|
||||||
s += &format!(" WHERE {}", selection.as_ref().to_string());
|
s += &format!(" WHERE {}", selection.to_string());
|
||||||
}
|
}
|
||||||
if let Some(ref group_by) = self.group_by {
|
if let Some(ref group_by) = self.group_by {
|
||||||
s += &format!(
|
s += &format!(
|
||||||
|
@ -50,7 +50,7 @@ impl ToString for SQLSelect {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(ref having) = self.having {
|
if let Some(ref having) = self.having {
|
||||||
s += &format!(" HAVING {}", having.as_ref().to_string());
|
s += &format!(" HAVING {}", having.to_string());
|
||||||
}
|
}
|
||||||
if let Some(ref order_by) = self.order_by {
|
if let Some(ref order_by) = self.order_by {
|
||||||
s += &format!(
|
s += &format!(
|
||||||
|
@ -63,7 +63,7 @@ impl ToString for SQLSelect {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Some(ref limit) = self.limit {
|
if let Some(ref limit) = self.limit {
|
||||||
s += &format!(" LIMIT {}", limit.as_ref().to_string());
|
s += &format!(" LIMIT {}", limit.to_string());
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl Parser {
|
||||||
}
|
}
|
||||||
Token::LParen => {
|
Token::LParen => {
|
||||||
let expr = if self.parse_keyword("SELECT") {
|
let expr = if self.parse_keyword("SELECT") {
|
||||||
ASTNode::SQLSubquery(self.parse_select()?)
|
ASTNode::SQLSubquery(Box::new(self.parse_select()?))
|
||||||
} else {
|
} else {
|
||||||
ASTNode::SQLNested(Box::new(self.parse_expr()?))
|
ASTNode::SQLNested(Box::new(self.parse_expr()?))
|
||||||
};
|
};
|
||||||
|
@ -1129,7 +1129,7 @@ impl Parser {
|
||||||
|
|
||||||
let selection = if self.parse_keyword("WHERE") {
|
let selection = if self.parse_keyword("WHERE") {
|
||||||
let expr = self.parse_expr()?;
|
let expr = self.parse_expr()?;
|
||||||
Some(Box::new(expr))
|
Some(expr)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -1141,7 +1141,7 @@ impl Parser {
|
||||||
};
|
};
|
||||||
|
|
||||||
let having = if self.parse_keyword("HAVING") {
|
let having = if self.parse_keyword("HAVING") {
|
||||||
Some(Box::new(self.parse_expr()?))
|
Some(self.parse_expr()?)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -1374,12 +1374,12 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a LIMIT clause
|
/// Parse a LIMIT clause
|
||||||
pub fn parse_limit(&mut self) -> Result<Option<Box<ASTNode>>, ParserError> {
|
pub fn parse_limit(&mut self) -> Result<Option<ASTNode>, ParserError> {
|
||||||
if self.parse_keyword("ALL") {
|
if self.parse_keyword("ALL") {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
} else {
|
} else {
|
||||||
self.parse_literal_int()
|
self.parse_literal_int()
|
||||||
.map(|n| Some(Box::new(ASTNode::SQLValue(Value::Long(n)))))
|
.map(|n| Some(ASTNode::SQLValue(Value::Long(n))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ fn parse_simple_select() {
|
||||||
projection, limit, ..
|
projection, limit, ..
|
||||||
}) => {
|
}) => {
|
||||||
assert_eq!(3, projection.len());
|
assert_eq!(3, projection.len());
|
||||||
assert_eq!(Some(Box::new(ASTNode::SQLValue(Value::Long(5)))), limit);
|
assert_eq!(Some(ASTNode::SQLValue(Value::Long(5))), limit);
|
||||||
}
|
}
|
||||||
_ => assert!(false),
|
_ => assert!(false),
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ fn parse_like() {
|
||||||
"%a".to_string()
|
"%a".to_string()
|
||||||
))),
|
))),
|
||||||
},
|
},
|
||||||
*selection.unwrap()
|
selection.unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => assert!(false),
|
_ => assert!(false),
|
||||||
|
@ -227,7 +227,7 @@ fn parse_not_like() {
|
||||||
"%a".to_string()
|
"%a".to_string()
|
||||||
))),
|
))),
|
||||||
},
|
},
|
||||||
*selection.unwrap()
|
selection.unwrap()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => assert!(false),
|
_ => assert!(false),
|
||||||
|
@ -287,7 +287,7 @@ fn parse_select_order_by_limit() {
|
||||||
]),
|
]),
|
||||||
order_by
|
order_by
|
||||||
);
|
);
|
||||||
assert_eq!(Some(Box::new(ASTNode::SQLValue(Value::Long(2)))), limit);
|
assert_eq!(Some(ASTNode::SQLValue(Value::Long(2))), limit);
|
||||||
}
|
}
|
||||||
_ => assert!(false),
|
_ => assert!(false),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue