Group a slice of window expression expr by their order by expressions
(
window_expr: impl IntoIterator<Item = Expr>,
)
| 620 | |
| 621 | /// Group a slice of window expression expr by their order by expressions |
| 622 | pub fn group_window_expr_by_sort_keys( |
| 623 | window_expr: impl IntoIterator<Item = Expr>, |
| 624 | ) -> Result<Vec<(WindowSortKey, Vec<Expr>)>> { |
| 625 | let mut result = vec![]; |
| 626 | window_expr.into_iter().try_for_each(|expr| match &expr { |
| 627 | Expr::WindowFunction(window_fun) => { |
| 628 | let WindowFunctionParams{ partition_by, order_by, ..} = &window_fun.as_ref().params; |
| 629 | let sort_key = generate_sort_key(partition_by, order_by)?; |
| 630 | if let Some((_, values)) = result.iter_mut().find( |
| 631 | |group: &&mut (WindowSortKey, Vec<Expr>)| matches!(group, (key, _) if *key == sort_key), |
| 632 | ) { |
| 633 | values.push(expr); |
| 634 | } else { |
| 635 | result.push((sort_key, vec![expr])) |
| 636 | } |
| 637 | Ok(()) |
| 638 | } |
| 639 | other => internal_err!( |
| 640 | "Impossibly got non-window expr {other:?}" |
| 641 | ), |
| 642 | })?; |
| 643 | Ok(result) |
| 644 | } |
| 645 | |
| 646 | /// Collect all deeply nested `Expr::AggregateFunction`. |
| 647 | /// They are returned in order of occurrence (depth |
searching dependent graphs…