Skip to content

Commit

Permalink
Initial fix for rename perf issue
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth-vi committed Sep 24, 2024
1 parent 54218e7 commit 8128ce8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions crates/polars-plan/src/plans/functions/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@ pub(super) fn rename_impl(
existing: &[PlSmallStr],
new: &[PlSmallStr],
) -> PolarsResult<DataFrame> {
let positions = existing
.iter()
.map(|old| df.get_column_index(old))
.collect::<Vec<_>>();
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::<Vec<_>>()
} else {
existing
.iter()
.map(|old| df.get_column_index(old))
.collect::<Vec<_>>()
};

for (pos, name) in positions.iter().zip(new.iter()) {
// the column might be removed due to projection pushdown
Expand Down

0 comments on commit 8128ce8

Please sign in to comment.