From 8128ce8735a7402094f0d495cb695d6ef4eabdbb Mon Sep 17 00:00:00 2001 From: siddharthv Date: Tue, 24 Sep 2024 17:24:49 +0530 Subject: [PATCH] Initial fix for rename perf issue --- .../polars-plan/src/plans/functions/rename.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/polars-plan/src/plans/functions/rename.rs b/crates/polars-plan/src/plans/functions/rename.rs index 7a58101e3731..dcab222229b9 100644 --- a/crates/polars-plan/src/plans/functions/rename.rs +++ b/crates/polars-plan/src/plans/functions/rename.rs @@ -5,10 +5,21 @@ pub(super) fn rename_impl( existing: &[PlSmallStr], new: &[PlSmallStr], ) -> PolarsResult { - let positions = existing - .iter() - .map(|old| df.get_column_index(old)) - .collect::>(); + let positions = if existing.len() > 1 && df.get_columns().len() > 10 { + let schema = df.schema(); + existing + .iter() + .map(|old| match schema.get_full(old) { + Some((idx, _, _)) => Some(idx), + None => None, + }) + .collect::>() + } else { + existing + .iter() + .map(|old| df.get_column_index(old)) + .collect::>() + }; for (pos, name) in positions.iter().zip(new.iter()) { // the column might be removed due to projection pushdown