gruuya commented on code in PR #21052:
URL: https://github.com/apache/datafusion/pull/21052#discussion_r3056599401
##########
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:
Fair point, I replaced the clone with take, so we just replace the expr
in-place
```diff
diff --git a/datafusion/expr/src/logical_plan/builder.rs
b/datafusion/expr/src/logical_plan/builder.rs
index 1d257c775..188daa724 100644
--- a/datafusion/expr/src/logical_plan/builder.rs
+++ b/datafusion/expr/src/logical_plan/builder.rs
@@ -2017,7 +2017,7 @@ fn project_with_validation(
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());
+ *expr = std::mem::take(expr).alias(field.name());
}
}
}
```
--
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]