Don't Box<ASTNode> in SQLSelect

Instead change ASTNode::SQLSubquery to be Box<SQLSelect>
This commit is contained in:
Nickolay Ponomarev 2019-01-31 15:25:00 +03:00
parent c5bbfc33fd
commit e3b981a0e2
4 changed files with 17 additions and 17 deletions

View file

@ -76,7 +76,7 @@ pub enum ASTNode {
},
/// A parenthesized subquery `(SELECT ...)`, used in expression like
/// `SELECT (subquery) AS x` or `WHERE (subquery) = x`
SQLSubquery(SQLSelect),
SQLSubquery(Box<SQLSelect>),
}
impl ToString for ASTNode {

View file

@ -6,18 +6,18 @@ pub struct SQLSelect {
pub projection: Vec<ASTNode>,
/// FROM
pub relation: Option<TableFactor>,
// JOIN
/// JOIN
pub joins: Vec<Join>,
/// WHERE
pub selection: Option<Box<ASTNode>>,
pub selection: Option<ASTNode>,
/// ORDER BY
pub order_by: Option<Vec<SQLOrderByExpr>>,
/// GROUP BY
pub group_by: Option<Vec<ASTNode>>,
/// HAVING
pub having: Option<Box<ASTNode>>,
pub having: Option<ASTNode>,
/// LIMIT
pub limit: Option<Box<ASTNode>>,
pub limit: Option<ASTNode>,
}
impl ToString for SQLSelect {
@ -37,7 +37,7 @@ impl ToString for SQLSelect {
s += &join.to_string();
}
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 {
s += &format!(
@ -50,7 +50,7 @@ impl ToString for SQLSelect {
);
}
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 {
s += &format!(
@ -63,7 +63,7 @@ impl ToString for SQLSelect {
);
}
if let Some(ref limit) = self.limit {
s += &format!(" LIMIT {}", limit.as_ref().to_string());
s += &format!(" LIMIT {}", limit.to_string());
}
s
}

View file

@ -197,7 +197,7 @@ impl Parser {
}
Token::LParen => {
let expr = if self.parse_keyword("SELECT") {
ASTNode::SQLSubquery(self.parse_select()?)
ASTNode::SQLSubquery(Box::new(self.parse_select()?))
} else {
ASTNode::SQLNested(Box::new(self.parse_expr()?))
};
@ -1129,7 +1129,7 @@ impl Parser {
let selection = if self.parse_keyword("WHERE") {
let expr = self.parse_expr()?;
Some(Box::new(expr))
Some(expr)
} else {
None
};
@ -1141,7 +1141,7 @@ impl Parser {
};
let having = if self.parse_keyword("HAVING") {
Some(Box::new(self.parse_expr()?))
Some(self.parse_expr()?)
} else {
None
};
@ -1374,12 +1374,12 @@ impl Parser {
}
/// 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") {
Ok(None)
} else {
self.parse_literal_int()
.map(|n| Some(Box::new(ASTNode::SQLValue(Value::Long(n)))))
.map(|n| Some(ASTNode::SQLValue(Value::Long(n))))
}
}
}

View file

@ -54,7 +54,7 @@ fn parse_simple_select() {
projection, limit, ..
}) => {
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),
}
@ -207,7 +207,7 @@ fn parse_like() {
"%a".to_string()
))),
},
*selection.unwrap()
selection.unwrap()
);
}
_ => assert!(false),
@ -227,7 +227,7 @@ fn parse_not_like() {
"%a".to_string()
))),
},
*selection.unwrap()
selection.unwrap()
);
}
_ => assert!(false),
@ -287,7 +287,7 @@ fn parse_select_order_by_limit() {
]),
order_by
);
assert_eq!(Some(Box::new(ASTNode::SQLValue(Value::Long(2)))), limit);
assert_eq!(Some(ASTNode::SQLValue(Value::Long(2))), limit);
}
_ => assert!(false),
}