Path: blob/main/crates/polars-plan/src/plans/optimizer/projection_pushdown/generic.rs
7889 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>,11) -> PolarsResult<IR> {12let inputs = lp.get_inputs();13let input_count = inputs.len();1415// let mut first_schema = None;16// let mut names = None;1718let new_inputs = inputs19.into_iter()20.map(|node| {21let alp = lp_arena.take(node);22let mut alp = proj_pd.push_down(alp, ctx.clone(), lp_arena, expr_arena)?;2324// double projection can mess up the schema ordering25// here we ensure the ordering is maintained.26//27// Consider this query28// df1 => a, b29// df2 => a, b30//31// df3 = df1.join(df2, on = a, b)32//33// concat([df1, df3]).select(a)34//35// schema after projection pd36// df3 => a, b37// df1 => a38// so we ensure we do the 'a' projection again before we concatenate39if !ctx.acc_projections.is_empty() && input_count > 1 {40alp = IRBuilder::from_lp(alp, expr_arena, lp_arena)41.project_simple_nodes(ctx.acc_projections.iter().map(|e| e.0))42.unwrap()43.build();44}45lp_arena.replace(node, alp);46Ok(node)47})48.collect::<PolarsResult<UnitVec<_>>>()?;4950Ok(lp.with_inputs(new_inputs))51}525354