mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
Fix: GROUPING SETS accept values without parenthesis (#1867)
This commit is contained in:
parent
80d47eee84
commit
394a534486
2 changed files with 39 additions and 1 deletions
|
@ -2822,6 +2822,38 @@ fn parse_group_by_special_grouping_sets() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_group_by_grouping_sets_single_values() {
|
||||
let sql = "SELECT a, b, SUM(c) FROM tab1 GROUP BY a, b GROUPING SETS ((a, b), a, (b), c, ())";
|
||||
let canonical =
|
||||
"SELECT a, b, SUM(c) FROM tab1 GROUP BY a, b GROUPING SETS ((a, b), (a), (b), (c), ())";
|
||||
match all_dialects().one_statement_parses_to(sql, canonical) {
|
||||
Statement::Query(query) => {
|
||||
let group_by = &query.body.as_select().unwrap().group_by;
|
||||
assert_eq!(
|
||||
group_by,
|
||||
&GroupByExpr::Expressions(
|
||||
vec![
|
||||
Expr::Identifier(Ident::new("a")),
|
||||
Expr::Identifier(Ident::new("b"))
|
||||
],
|
||||
vec![GroupByWithModifier::GroupingSets(Expr::GroupingSets(vec![
|
||||
vec![
|
||||
Expr::Identifier(Ident::new("a")),
|
||||
Expr::Identifier(Ident::new("b"))
|
||||
],
|
||||
vec![Expr::Identifier(Ident::new("a"))],
|
||||
vec![Expr::Identifier(Ident::new("b"))],
|
||||
vec![Expr::Identifier(Ident::new("c"))],
|
||||
vec![]
|
||||
]))]
|
||||
)
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_select_having() {
|
||||
let sql = "SELECT foo FROM bar GROUP BY foo HAVING COUNT(*) > 1";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue