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


##########
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 tried fixing this at the logical->physical layer in 
https://github.com/apache/datafusion/pull/27718. It's a pretty simple change, 
and it should work regardless of how the logical plan schemas happen to be laid 
out across analyzer/optimizer passes.



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