gabotechs commented on code in PR #27573:
URL: https://github.com/apache/datafusion/pull/27573#discussion_r4678703107


##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -452,7 +452,29 @@ impl<'a> TypeCoercionRewriter<'a> {
                             Arc::clone(&union_schema),
                         )?))
                     }
-                    other_plan => Ok(Arc::new(other_plan)),
+                    other_plan => {
+                        let needs_rename = other_plan
+                            .schema()
+                            .fields()
+                            .iter()
+                            .zip(union_schema.fields())
+                            .any(|(input, output)| input.name() != 
output.name());
+                        if needs_rename {
+                            let expr = other_plan
+                                .schema()
+                                .columns()
+                                .into_iter()
+                                .map(Expr::Column)
+                                .collect();
+                            Ok(Arc::new(project_with_column_index(
+                                expr,
+                                Arc::new(other_plan),
+                                Arc::clone(&union_schema),
+                            )?))
+                        } else {
+                            Ok(Arc::new(other_plan))
+                        }
+                    }

Review Comment:
   I'm not sure if this is added to the appropriate place. This struct is in 
charge of type coercion, but it's not the types which we are trying to coerce 
here, it's just the column names that do not match.
   
   I get the impression that this is better solved where the the name mismatch 
is created, during logical->physical conversion



-- 
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]

Reply via email to