Path: blob/main/crates/polars-plan/src/plans/optimizer/projection_pushdown/hstack.rs
7889 views
use super::*;12#[allow(clippy::too_many_arguments)]3pub(super) fn process_hstack(4proj_pd: &mut ProjectionPushDown,5input: Node,6mut exprs: Vec<ExprIR>,7options: ProjectionOptions,8mut ctx: ProjectionContext,9lp_arena: &mut Arena<IR>,10expr_arena: &mut Arena<AExpr>,11) -> PolarsResult<IR> {12if ctx.has_pushed_down() {13let mut pruned_with_cols = Vec::with_capacity(exprs.len());1415// Check if output names are used upstream16// if not, we can prune the `with_column` expression17// as it is not used in the output.18for e in exprs {19let is_used_upstream = ctx.projected_names.contains(e.output_name());20if is_used_upstream {21pruned_with_cols.push(e);22}23}2425if pruned_with_cols.is_empty() {26proj_pd.pushdown_and_assign(input, ctx, lp_arena, expr_arena)?;27return Ok(lp_arena.take(input));28}2930// Make sure that columns selected with_columns are available31// only if not empty. If empty we already select everything.32for e in &pruned_with_cols {33add_expr_to_accumulated(34e.node(),35&mut ctx.acc_projections,36&mut ctx.projected_names,37expr_arena,38);39}4041exprs = pruned_with_cols42}43// projections that select columns added by44// this `with_column` operation can be dropped45// For instance in:46//47// q48// .with_column(col("a").alias("b")49// .select(["a", "b"])50//51// we can drop the "b" projection at this level52let (acc_projections, _, names) = split_acc_projections(53ctx.acc_projections,54&lp_arena.get(input).schema(lp_arena),55expr_arena,56true, // expands_schema57);5859let ctx = ProjectionContext::new(acc_projections, names, ctx.inner);60proj_pd.pushdown_and_assign(input, ctx, lp_arena, expr_arena)?;6162let lp = IRBuilder::new(input, expr_arena, lp_arena)63.with_columns(exprs, options)64.build();65Ok(lp)66}676869