Path: blob/main/crates/polars-plan/src/plans/optimizer/projection_pushdown/hconcat.rs
7889 views
use super::*;12#[allow(clippy::too_many_arguments)]3pub(super) fn process_hconcat(4proj_pd: &mut ProjectionPushDown,5mut inputs: Vec<Node>,6schema: SchemaRef,7options: HConcatOptions,8ctx: ProjectionContext,9lp_arena: &mut Arena<IR>,10expr_arena: &mut Arena<AExpr>,11) -> PolarsResult<IR> {12// When applying projection pushdown to horizontal concatenation,13// we apply pushdown to all of the inputs using the subset of accumulated projections relevant to each input,14// then rebuild the concatenated schema.1516let schema = if ctx.acc_projections.is_empty() {17schema18} else {19let mut remaining_projections: PlHashSet<_> = ctx.acc_projections.into_iter().collect();2021let mut result = Ok(());22inputs.retain(|input| {23let mut input_pushdown = Vec::new();24let input_schema = lp_arena.get(*input).schema(lp_arena);2526for proj in remaining_projections.iter() {27if check_input_column_node(*proj, input_schema.as_ref(), expr_arena) {28input_pushdown.push(*proj);29}30}3132if input_pushdown.is_empty() {33// we can ignore this input since no columns are needed34if options.strict {35return false;36}37// we read a single column (needed to compute the correct height)38if let Some((name, _)) = input_schema.get_at_index(0) {39let node = expr_arena.add(AExpr::Column(name.clone()));40input_pushdown.push(ColumnNode(node));41}42}4344let mut input_names = PlHashSet::new();45for proj in &input_pushdown {46remaining_projections.remove(proj);47for name in aexpr_to_leaf_names(proj.0, expr_arena) {48input_names.insert(name);49}50}51let ctx = ProjectionContext::new(input_pushdown, input_names, ctx.inner);52if let Err(e) = proj_pd.pushdown_and_assign(*input, ctx, lp_arena, expr_arena) {53result = Err(e);54}55true56});57result?;5859let mut schemas = Vec::with_capacity(inputs.len());60for input in inputs.iter() {61let schema = lp_arena.get(*input).schema(lp_arena).into_owned();62schemas.push(schema);63}64let new_schema = merge_schemas(&schemas)?;65Arc::new(new_schema)66};6768Ok(IR::HConcat {69inputs,70schema,71options,72})73}747576