Path: blob/main/crates/polars-plan/src/plans/optimizer/projection_pushdown/generic.rs
8430 views
use polars_utils::idx_vec::UnitVec;12use super::*;34#[allow(clippy::too_many_arguments)]5pub(super) fn process_generic(6proj_pd: &mut ProjectionPushDown,7lp: IR,8ctx: ProjectionContext,9lp_arena: &mut Arena<IR>,10expr_arena: &mut Arena<AExpr>,11reset_count_star: bool,12) -> PolarsResult<IR> {13let inputs = lp.get_inputs();14let input_count = inputs.len();1516// let mut first_schema = None;17// let mut names = None;1819let new_inputs = inputs20.into_iter()21.map(|node| {22if reset_count_star {23proj_pd.is_count_star = false;24}25let alp = lp_arena.take(node);26let mut alp = proj_pd.push_down(alp, ctx.clone(), lp_arena, expr_arena)?;2728// double projection can mess up the schema ordering29// here we ensure the ordering is maintained.30//31// Consider this query32// df1 => a, b33// df2 => a, b34//35// df3 = df1.join(df2, on = a, b)36//37// concat([df1, df3]).select(a)38//39// schema after projection pd40// df3 => a, b41// df1 => a42// so we ensure we do the 'a' projection again before we concatenate43if !ctx.acc_projections.is_empty() && input_count > 1 {44alp = IRBuilder::from_lp(alp, expr_arena, lp_arena)45.project_simple_nodes(ctx.acc_projections.iter().map(|e| e.0))46.unwrap()47.build();48}49lp_arena.replace(node, alp);50Ok(node)51})52.collect::<PolarsResult<UnitVec<_>>>()?;5354Ok(lp.with_inputs(new_inputs))55}565758