mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-04 14:28:22 +00:00
Add supports for Hive's SELECT ... GROUP BY .. GROUPING SETS
syntax (#1653)
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
parent
a5bbb5e8ac
commit
1c0e5d3554
8 changed files with 132 additions and 60 deletions
|
@ -1069,61 +1069,6 @@ fn parse_create_materialized_view() {
|
|||
clickhouse_and_generic().verified_stmt(sql);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_group_by_with_modifier() {
|
||||
let clauses = ["x", "a, b", "ALL"];
|
||||
let modifiers = [
|
||||
"WITH ROLLUP",
|
||||
"WITH CUBE",
|
||||
"WITH TOTALS",
|
||||
"WITH ROLLUP WITH CUBE",
|
||||
];
|
||||
let expected_modifiers = [
|
||||
vec![GroupByWithModifier::Rollup],
|
||||
vec![GroupByWithModifier::Cube],
|
||||
vec![GroupByWithModifier::Totals],
|
||||
vec![GroupByWithModifier::Rollup, GroupByWithModifier::Cube],
|
||||
];
|
||||
for clause in &clauses {
|
||||
for (modifier, expected_modifier) in modifiers.iter().zip(expected_modifiers.iter()) {
|
||||
let sql = format!("SELECT * FROM t GROUP BY {clause} {modifier}");
|
||||
match clickhouse_and_generic().verified_stmt(&sql) {
|
||||
Statement::Query(query) => {
|
||||
let group_by = &query.body.as_select().unwrap().group_by;
|
||||
if clause == &"ALL" {
|
||||
assert_eq!(group_by, &GroupByExpr::All(expected_modifier.to_vec()));
|
||||
} else {
|
||||
assert_eq!(
|
||||
group_by,
|
||||
&GroupByExpr::Expressions(
|
||||
clause
|
||||
.split(", ")
|
||||
.map(|c| Identifier(Ident::new(c)))
|
||||
.collect(),
|
||||
expected_modifier.to_vec()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// invalid cases
|
||||
let invalid_cases = [
|
||||
"SELECT * FROM t GROUP BY x WITH",
|
||||
"SELECT * FROM t GROUP BY x WITH ROLLUP CUBE",
|
||||
"SELECT * FROM t GROUP BY x WITH WITH ROLLUP",
|
||||
"SELECT * FROM t GROUP BY WITH ROLLUP",
|
||||
];
|
||||
for sql in invalid_cases {
|
||||
clickhouse_and_generic()
|
||||
.parse_sql_statements(sql)
|
||||
.expect_err("Expected: one of ROLLUP or CUBE or TOTALS, found: WITH");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_select_order_by_with_fill_interpolate() {
|
||||
let sql = "SELECT id, fname, lname FROM customer WHERE id < 5 \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue