comphead commented on code in PR #12431:
URL: https://github.com/apache/datafusion/pull/12431#discussion_r1754965635
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -1452,28 +1452,34 @@ impl DataFrame {
pub fn with_column(self, name: &str, expr: Expr) -> Result<DataFrame> {
let window_func_exprs = find_window_exprs(&[expr.clone()]);
- let (plan, mut col_exists, window_func) = if
window_func_exprs.is_empty() {
- (self.plan, false, false)
+ let (window_fn_str, plan) = if window_func_exprs.is_empty() {
+ (None, self.plan)
} else {
(
+ Some(window_func_exprs[0].to_string()),
LogicalPlanBuilder::window_plan(self.plan, window_func_exprs)?,
- true,
- true,
)
};
+ let mut col_exists = false;
let new_column = expr.alias(name);
let mut fields: Vec<Expr> = plan
.schema()
.iter()
- .map(|(qualifier, field)| {
+ .filter_map(|(qualifier, field)| {
if field.name() == name {
col_exists = true;
- new_column.clone()
- } else if window_func && qualifier.is_none() {
- col(Column::from((qualifier, field))).alias(name)
+ Some(new_column.clone())
} else {
- col(Column::from((qualifier, field)))
+ let e = col(Column::from((qualifier, field)));
+ let match_window_fn = window_fn_str
+ .as_ref()
Review Comment:
I feel this can be replaced by the 1 liner, see example below
```
fn main() {
let e: String = "a".to_string();
let x: Option<String> = Some("s".to_string());
println!("{:?}", x.filter(|s| *s == e).is_none().then_some(e));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]