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:
Renaming already happens here for `Projection` inputs, but the analyzer only
runs once, before the optimizer, so rules like `propagate_empty_relation` can
recreate the mismatch afterwards (#27611). Logical unions match columns by
position, so the names only start to matter when `UnionExec` takes them from
its first input. Aligning them during physical planning covers every case; I
tried that in #27718.
--
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]