jackwener commented on code in PR #8438:
URL: https://github.com/apache/arrow-datafusion/pull/8438#discussion_r1418253641
##########
datafusion/optimizer/src/optimize_projections.rs:
##########
@@ -405,9 +405,25 @@ fn merge_consecutive_projections(proj: &Projection) ->
Result<Option<Projection>
.iter()
.map(|expr| rewrite_expr(expr, prev_projection))
.collect::<Result<Option<Vec<_>>>>()?;
- new_exprs
- .map(|exprs| Projection::try_new(exprs, prev_projection.input.clone()))
- .transpose()
+ if let Some(new_exprs) = new_exprs {
+ let new_exprs = new_exprs
+ .into_iter()
+ .zip(proj.expr.iter())
+ .map(|(new_expr, old_expr)| {
+ let new_name = new_expr.name_for_alias()?;
+ let old_name = old_expr.name_for_alias()?;
+ Ok(if new_name != old_name {
+ // Make sure name is preserved after merging
+ new_expr.alias(old_name)
+ } else {
+ new_expr
+ })
Review Comment:
```suggestion
new_expr.alias_if_changed(old_expr.name_for_alias()?)
```
--
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]