fn window(
        &self,
        input: LogicalPlan,
        window_exprs: Vec<Expr>,
        select_exprs: &[Expr],
    ) -> Result<(LogicalPlan, Vec<Expr>)> {
        let mut plan = input;
        let mut groups = group_window_expr_by_sort_keys(&window_exprs)?;
        // sort by sort_key len descending, so that more deeply sorted plans gets nested further
        // down as children; to further minic the behavior of PostgreSQL, we want stable sort
        // and a reverse so that tieing sort keys are reversed in order; note that by this rule
        // if there's an empty over, it'll be at the top level
        groups.sort_by(|(key_a, _), (key_b, _)| key_a.len().cmp(&key_b.len()));
        groups.reverse();
        for (sort_keys, exprs) in groups {
            if !sort_keys.is_empty() {
                let sort_keys: Vec<Expr> = sort_keys.to_vec();
                plan = LogicalPlanBuilder::from(&plan).sort(sort_keys)?.build()?;
            }
            let window_exprs: Vec<Expr> = exprs.into_iter().cloned().collect();
            plan = LogicalPlanBuilder::from(&plan)
                .window(window_exprs)?
                .build()?;
        }
        let select_exprs = select_exprs
            .iter()
            .map(|expr| rebase_expr(expr, &window_exprs, &plan))
            .into_iter()
            .collect::<Result<Vec<_>>>()?;
        Ok((plan, select_exprs))
    }
/// Wrap a plan in a window
Wrap a plan in a window
Wrap a plan in a window
fn window(
        &self,
        input: LogicalPlan,
        window_exprs: Vec<Expr>,
        select_exprs: &[Expr],
    ) -> Result<(LogicalPlan, Vec<Expr>)> {
        let mut plan = input;
        let mut groups = group_window_expr_by_sort_keys(&window_exprs)?;
        // sort by sort_key len descending, so that more deeply sorted plans gets nested further
        // down as children; to further minic the behavior of PostgreSQL, we want stable sort
        // and a reverse so that tieing sort keys are reversed in order; note that by this rule
        // if there's an empty over, it'll be at the top level
        groups.sort_by(|(key_a, _), (key_b, _)| key_a.len().cmp(&key_b.len()));
        groups.reverse();
        for (sort_keys, exprs) in groups {
            if !sort_keys.is_empty() {
                let sort_keys: Vec<Expr> = sort_keys.to_vec();
                plan = LogicalPlanBuilder::from(&plan).sort(sort_keys)?.build()?;
            }
            let window_exprs: Vec<Expr> = exprs.into_iter().cloned().collect();
            plan = LogicalPlanBuilder::from(&plan)
                .window(window_exprs)?
                .build()?;
        }
        let select_exprs = select_exprs
            .iter()
            .map(|expr| rebase_expr(expr, &window_exprs, &plan))
            .into_iter()
            .collect::<Result<Vec<_>>>()?;
        Ok((plan, select_exprs))
    }
fn window ( & self , input : LogicalPlan , window_exprs : Vec < Expr > , select_exprs : & [ Expr ] , ) -> Result < ( LogicalPlan , Vec < Expr > ) > { let mut plan = input ; let mut groups = group_window_expr_by_sort_keys ( & window_exprs ) ? ; // sort by sort_key len descending, so that more deeply sorted plans gets nested further // down as children; to further minic the behavior of PostgreSQL, we want stable sort // and a reverse so that tieing sort keys are reversed in order; note that by this rule // if there's an empty over, it'll be at the top level groups . sort_by ( | ( key_a , _ ) , ( key_b , _ ) | key_a . len ( ) . cmp ( & key_b . len ( ) ) ) ; groups . reverse ( ) ; for ( sort_keys , exprs ) in groups { if ! sort_keys . is_empty ( ) { let sort_keys : Vec < Expr > = sort_keys . to_vec ( ) ; plan = LogicalPlanBuilder :: from ( & plan ) . sort ( sort_keys ) ? . build ( ) ? ; } let window_exprs : Vec < Expr > = exprs . into_iter ( ) . cloned ( ) . collect ( ) ; plan = LogicalPlanBuilder :: from ( & plan ) . window ( window_exprs ) ? . build ( ) ? ; } let select_exprs = select_exprs . iter ( ) . map ( | expr | rebase_expr ( expr , & window_exprs , & plan ) ) . into_iter ( ) . collect :: < Result < Vec < _ > > > ( ) ? ; Ok ( ( plan , select_exprs ) ) }
Wrap a plan in a window
Wrap a plan in a window
&self
input
LogicalPlan
window_exprs
Vec<Expr>
select_exprs
&[Expr]
&self
input
LogicalPlan
window_exprs
Vec<Expr>
select_exprs
&[Expr]