Skip to content

Commit 353b889

Browse files
committed
fix: Fix redundant column when using window function
1 parent c609dfa commit 353b889

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/dataframe.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::collections::HashMap;
1919
use std::ffi::CString;
2020
use std::sync::Arc;
2121

22+
use crate::datafusion_expr::Expr;
2223
use arrow::array::{new_null_array, RecordBatch, RecordBatchIterator, RecordBatchReader};
2324
use arrow::compute::can_cast_types;
2425
use arrow::error::ArrowError;
@@ -473,7 +474,19 @@ impl PyDataFrame {
473474
}
474475

475476
fn with_column(&self, name: &str, expr: PyExpr) -> PyDataFusionResult<Self> {
476-
let df = self.df.as_ref().clone().with_column(name, expr.into())?;
477+
let expr: Expr = expr.into();
478+
let aliased = expr.alias(name);
479+
480+
let df_schema = self.df.as_ref().schema().clone();
481+
let mut proj_exprs: Vec<Expr> = df_schema
482+
.fields()
483+
.iter()
484+
.filter(|field| field.name() != name)
485+
.map(|field| col(field.name()))
486+
.collect();
487+
proj_exprs.push(aliased);
488+
489+
let df = self.df.as_ref().clone().select(proj_exprs)?;
477490
Ok(Self::new(df))
478491
}
479492

0 commit comments

Comments
 (0)