mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-03 04:37:21 +00:00
Boxed Query body to save some stack space (#540)
This commit is contained in:
parent
5363d4e399
commit
dea7666086
6 changed files with 24 additions and 24 deletions
|
@ -26,7 +26,7 @@ pub struct Query {
|
||||||
/// WITH (common table expressions, or CTEs)
|
/// WITH (common table expressions, or CTEs)
|
||||||
pub with: Option<With>,
|
pub with: Option<With>,
|
||||||
/// SELECT or UNION / EXCEPT / INTERSECT
|
/// SELECT or UNION / EXCEPT / INTERSECT
|
||||||
pub body: SetExpr,
|
pub body: Box<SetExpr>,
|
||||||
/// ORDER BY
|
/// ORDER BY
|
||||||
pub order_by: Vec<OrderByExpr>,
|
pub order_by: Vec<OrderByExpr>,
|
||||||
/// `LIMIT { <N> | ALL }`
|
/// `LIMIT { <N> | ALL }`
|
||||||
|
|
|
@ -3216,7 +3216,7 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if !self.parse_keyword(Keyword::INSERT) {
|
if !self.parse_keyword(Keyword::INSERT) {
|
||||||
let body = self.parse_query_body(0)?;
|
let body = Box::new(self.parse_query_body(0)?);
|
||||||
|
|
||||||
let order_by = if self.parse_keywords(&[Keyword::ORDER, Keyword::BY]) {
|
let order_by = if self.parse_keywords(&[Keyword::ORDER, Keyword::BY]) {
|
||||||
self.parse_comma_separated(Parser::parse_order_by_expr)?
|
self.parse_comma_separated(Parser::parse_order_by_expr)?
|
||||||
|
@ -3268,7 +3268,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
Ok(Query {
|
Ok(Query {
|
||||||
with,
|
with,
|
||||||
body: SetExpr::Insert(insert),
|
body: Box::new(SetExpr::Insert(insert)),
|
||||||
limit: None,
|
limit: None,
|
||||||
order_by: vec![],
|
order_by: vec![],
|
||||||
offset: None,
|
offset: None,
|
||||||
|
|
|
@ -115,7 +115,7 @@ impl TestedDialects {
|
||||||
/// Ensures that `sql` parses as a single [Select], and is not modified
|
/// Ensures that `sql` parses as a single [Select], and is not modified
|
||||||
/// after a serialization round-trip.
|
/// after a serialization round-trip.
|
||||||
pub fn verified_only_select(&self, query: &str) -> Select {
|
pub fn verified_only_select(&self, query: &str) -> Select {
|
||||||
match self.verified_query(query).body {
|
match *self.verified_query(query).body {
|
||||||
SetExpr::Select(s) => *s,
|
SetExpr::Select(s) => *s,
|
||||||
_ => panic!("Expected SetExpr::Select"),
|
_ => panic!("Expected SetExpr::Select"),
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ fn parse_insert_values() {
|
||||||
for (index, column) in columns.iter().enumerate() {
|
for (index, column) in columns.iter().enumerate() {
|
||||||
assert_eq!(column, &Ident::new(expected_columns[index].clone()));
|
assert_eq!(column, &Ident::new(expected_columns[index].clone()));
|
||||||
}
|
}
|
||||||
match &source.body {
|
match &*source.body {
|
||||||
SetExpr::Values(Values(values)) => assert_eq!(values.as_slice(), expected_rows),
|
SetExpr::Values(Values(values)) => assert_eq!(values.as_slice(), expected_rows),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
@ -3988,7 +3988,7 @@ fn parse_offset() {
|
||||||
assert_eq!(ast.offset, expect);
|
assert_eq!(ast.offset, expect);
|
||||||
let ast = verified_query("SELECT foo FROM (SELECT * FROM bar OFFSET 2 ROWS) OFFSET 2 ROWS");
|
let ast = verified_query("SELECT foo FROM (SELECT * FROM bar OFFSET 2 ROWS) OFFSET 2 ROWS");
|
||||||
assert_eq!(ast.offset, expect);
|
assert_eq!(ast.offset, expect);
|
||||||
match ast.body {
|
match *ast.body {
|
||||||
SetExpr::Select(s) => match only(s.from).relation {
|
SetExpr::Select(s) => match only(s.from).relation {
|
||||||
TableFactor::Derived { subquery, .. } => {
|
TableFactor::Derived { subquery, .. } => {
|
||||||
assert_eq!(subquery.offset, expect);
|
assert_eq!(subquery.offset, expect);
|
||||||
|
@ -4082,7 +4082,7 @@ fn parse_fetch() {
|
||||||
"SELECT foo FROM (SELECT * FROM bar FETCH FIRST 2 ROWS ONLY) FETCH FIRST 2 ROWS ONLY",
|
"SELECT foo FROM (SELECT * FROM bar FETCH FIRST 2 ROWS ONLY) FETCH FIRST 2 ROWS ONLY",
|
||||||
);
|
);
|
||||||
assert_eq!(ast.fetch, fetch_first_two_rows_only);
|
assert_eq!(ast.fetch, fetch_first_two_rows_only);
|
||||||
match ast.body {
|
match *ast.body {
|
||||||
SetExpr::Select(s) => match only(s.from).relation {
|
SetExpr::Select(s) => match only(s.from).relation {
|
||||||
TableFactor::Derived { subquery, .. } => {
|
TableFactor::Derived { subquery, .. } => {
|
||||||
assert_eq!(subquery.fetch, fetch_first_two_rows_only);
|
assert_eq!(subquery.fetch, fetch_first_two_rows_only);
|
||||||
|
@ -4100,7 +4100,7 @@ fn parse_fetch() {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
assert_eq!(ast.fetch, fetch_first_two_rows_only);
|
assert_eq!(ast.fetch, fetch_first_two_rows_only);
|
||||||
match ast.body {
|
match *ast.body {
|
||||||
SetExpr::Select(s) => match only(s.from).relation {
|
SetExpr::Select(s) => match only(s.from).relation {
|
||||||
TableFactor::Derived { subquery, .. } => {
|
TableFactor::Derived { subquery, .. } => {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -4638,7 +4638,7 @@ fn parse_merge() {
|
||||||
lateral: false,
|
lateral: false,
|
||||||
subquery: Box::new(Query {
|
subquery: Box::new(Query {
|
||||||
with: None,
|
with: None,
|
||||||
body: SetExpr::Select(Box::new(Select {
|
body: Box::new(SetExpr::Select(Box::new(Select {
|
||||||
distinct: false,
|
distinct: false,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![SelectItem::Wildcard],
|
projection: vec![SelectItem::Wildcard],
|
||||||
|
@ -4660,7 +4660,7 @@ fn parse_merge() {
|
||||||
sort_by: vec![],
|
sort_by: vec![],
|
||||||
having: None,
|
having: None,
|
||||||
qualify: None,
|
qualify: None,
|
||||||
})),
|
}))),
|
||||||
order_by: vec![],
|
order_by: vec![],
|
||||||
limit: None,
|
limit: None,
|
||||||
offset: None,
|
offset: None,
|
||||||
|
|
|
@ -313,7 +313,7 @@ fn parse_quote_identifiers_2() {
|
||||||
mysql().verified_stmt(sql),
|
mysql().verified_stmt(sql),
|
||||||
Statement::Query(Box::new(Query {
|
Statement::Query(Box::new(Query {
|
||||||
with: None,
|
with: None,
|
||||||
body: SetExpr::Select(Box::new(Select {
|
body: Box::new(SetExpr::Select(Box::new(Select {
|
||||||
distinct: false,
|
distinct: false,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident {
|
projection: vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident {
|
||||||
|
@ -330,7 +330,7 @@ fn parse_quote_identifiers_2() {
|
||||||
sort_by: vec![],
|
sort_by: vec![],
|
||||||
having: None,
|
having: None,
|
||||||
qualify: None
|
qualify: None
|
||||||
})),
|
}))),
|
||||||
order_by: vec![],
|
order_by: vec![],
|
||||||
limit: None,
|
limit: None,
|
||||||
offset: None,
|
offset: None,
|
||||||
|
@ -347,7 +347,7 @@ fn parse_quote_identifiers_3() {
|
||||||
mysql().verified_stmt(sql),
|
mysql().verified_stmt(sql),
|
||||||
Statement::Query(Box::new(Query {
|
Statement::Query(Box::new(Query {
|
||||||
with: None,
|
with: None,
|
||||||
body: SetExpr::Select(Box::new(Select {
|
body: Box::new(SetExpr::Select(Box::new(Select {
|
||||||
distinct: false,
|
distinct: false,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident {
|
projection: vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident {
|
||||||
|
@ -364,7 +364,7 @@ fn parse_quote_identifiers_3() {
|
||||||
sort_by: vec![],
|
sort_by: vec![],
|
||||||
having: None,
|
having: None,
|
||||||
qualify: None
|
qualify: None
|
||||||
})),
|
}))),
|
||||||
order_by: vec![],
|
order_by: vec![],
|
||||||
limit: None,
|
limit: None,
|
||||||
offset: None,
|
offset: None,
|
||||||
|
@ -392,7 +392,7 @@ fn parse_escaped_string() {
|
||||||
let stmt = mysql().one_statement_parses_to(sql, "");
|
let stmt = mysql().one_statement_parses_to(sql, "");
|
||||||
|
|
||||||
match stmt {
|
match stmt {
|
||||||
Statement::Query(query) => match query.body {
|
Statement::Query(query) => match *query.body {
|
||||||
SetExpr::Select(value) => {
|
SetExpr::Select(value) => {
|
||||||
let expr = expr_from_projection(only(&value.projection));
|
let expr = expr_from_projection(only(&value.projection));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -517,7 +517,7 @@ fn parse_simple_insert() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Box::new(Query {
|
Box::new(Query {
|
||||||
with: None,
|
with: None,
|
||||||
body: SetExpr::Values(Values(vec![
|
body: Box::new(SetExpr::Values(Values(vec![
|
||||||
vec![
|
vec![
|
||||||
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
|
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
|
||||||
Expr::Value(Value::Number("1".to_string(), false))
|
Expr::Value(Value::Number("1".to_string(), false))
|
||||||
|
@ -530,7 +530,7 @@ fn parse_simple_insert() {
|
||||||
Expr::Value(Value::SingleQuotedString("Test Entry 3".to_string())),
|
Expr::Value(Value::SingleQuotedString("Test Entry 3".to_string())),
|
||||||
Expr::Value(Value::Number("3".to_string(), false))
|
Expr::Value(Value::Number("3".to_string(), false))
|
||||||
]
|
]
|
||||||
])),
|
]))),
|
||||||
order_by: vec![],
|
order_by: vec![],
|
||||||
limit: None,
|
limit: None,
|
||||||
offset: None,
|
offset: None,
|
||||||
|
@ -574,7 +574,7 @@ fn parse_insert_with_on_duplicate_update() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Box::new(Query {
|
Box::new(Query {
|
||||||
with: None,
|
with: None,
|
||||||
body: SetExpr::Values(Values(vec![vec![
|
body: Box::new(SetExpr::Values(Values(vec![vec![
|
||||||
Expr::Value(Value::SingleQuotedString("accounting_manager".to_string())),
|
Expr::Value(Value::SingleQuotedString("accounting_manager".to_string())),
|
||||||
Expr::Value(Value::SingleQuotedString(
|
Expr::Value(Value::SingleQuotedString(
|
||||||
"Some description about the group".to_string()
|
"Some description about the group".to_string()
|
||||||
|
@ -583,7 +583,7 @@ fn parse_insert_with_on_duplicate_update() {
|
||||||
Expr::Value(Value::Boolean(true)),
|
Expr::Value(Value::Boolean(true)),
|
||||||
Expr::Value(Value::Boolean(true)),
|
Expr::Value(Value::Boolean(true)),
|
||||||
Expr::Value(Value::Boolean(true)),
|
Expr::Value(Value::Boolean(true)),
|
||||||
]])),
|
]]))),
|
||||||
order_by: vec![],
|
order_by: vec![],
|
||||||
limit: None,
|
limit: None,
|
||||||
offset: None,
|
offset: None,
|
||||||
|
@ -767,7 +767,7 @@ fn parse_substring_in_select() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Box::new(Query {
|
Box::new(Query {
|
||||||
with: None,
|
with: None,
|
||||||
body: SetExpr::Select(Box::new(Select {
|
body: Box::new(SetExpr::Select(Box::new(Select {
|
||||||
distinct: true,
|
distinct: true,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![SelectItem::UnnamedExpr(Expr::Substring {
|
projection: vec![SelectItem::UnnamedExpr(Expr::Substring {
|
||||||
|
@ -805,7 +805,7 @@ fn parse_substring_in_select() {
|
||||||
sort_by: vec![],
|
sort_by: vec![],
|
||||||
having: None,
|
having: None,
|
||||||
qualify: None
|
qualify: None
|
||||||
})),
|
}))),
|
||||||
order_by: vec![],
|
order_by: vec![],
|
||||||
limit: None,
|
limit: None,
|
||||||
offset: None,
|
offset: None,
|
||||||
|
|
|
@ -427,7 +427,7 @@ fn parse_update_set_from() {
|
||||||
lateral: false,
|
lateral: false,
|
||||||
subquery: Box::new(Query {
|
subquery: Box::new(Query {
|
||||||
with: None,
|
with: None,
|
||||||
body: SetExpr::Select(Box::new(Select {
|
body: Box::new(SetExpr::Select(Box::new(Select {
|
||||||
distinct: false,
|
distinct: false,
|
||||||
top: None,
|
top: None,
|
||||||
projection: vec![
|
projection: vec![
|
||||||
|
@ -452,7 +452,7 @@ fn parse_update_set_from() {
|
||||||
sort_by: vec![],
|
sort_by: vec![],
|
||||||
having: None,
|
having: None,
|
||||||
qualify: None
|
qualify: None
|
||||||
})),
|
}))),
|
||||||
order_by: vec![],
|
order_by: vec![],
|
||||||
limit: None,
|
limit: None,
|
||||||
offset: None,
|
offset: None,
|
||||||
|
@ -1042,7 +1042,7 @@ fn parse_prepare() {
|
||||||
Expr::Identifier("a2".into()),
|
Expr::Identifier("a2".into()),
|
||||||
Expr::Identifier("a3".into()),
|
Expr::Identifier("a3".into()),
|
||||||
]];
|
]];
|
||||||
match &source.body {
|
match &*source.body {
|
||||||
SetExpr::Values(Values(values)) => assert_eq!(values.as_slice(), &expected_values),
|
SetExpr::Values(Values(values)) => assert_eq!(values.as_slice(), &expected_values),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue