MCPcopy Create free account
hub / github.com/apache/datafusion / group_window_expr_by_sort_keys

Function group_window_expr_by_sort_keys

datafusion/expr/src/utils.rs:622–644  ·  view source on GitHub ↗

Group a slice of window expression expr by their order by expressions

(
    window_expr: impl IntoIterator<Item = Expr>,
)

Source from the content-addressed store, hash-verified

620
621/// Group a slice of window expression expr by their order by expressions
622pub 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

Calls 4

generate_sort_keyFunction · 0.85
into_iterMethod · 0.45
as_refMethod · 0.45
pushMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…