jonahgao commented on code in PR #21052:
URL: https://github.com/apache/datafusion/pull/21052#discussion_r3056482392
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -1984,6 +2001,17 @@ fn project_with_validation(
}
}
}
+
+ // When inside a set expression, alias non-Column/non-Alias expressions
+ // to match the left side's field names, avoiding duplicate name errors.
+ if let Some(schema) = &schema {
+ for (expr, field) in projected_expr.iter_mut().zip(schema.fields()) {
+ if !matches!(expr, Expr::Column(_) | Expr::Alias(_)) {
+ *expr = expr.clone().alias(field.name());
Review Comment:
Cloning an expression is typically expensive. How about
```rust
projected_expr = projected_expr
.into_iter()
.zip(schema.fields().iter())
.map(|(expr, field)| {
if !matches!(expr, Expr::Column(_) | Expr::Alias(_)) {
expr.alias(field.name())
} else {
expr
}
})
.collect();
```
--
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]