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


##########
datafusion/optimizer/src/propagate_empty_relation.rs:
##########
@@ -195,23 +195,25 @@ impl OptimizerRule for PropagateEmptyRelation {
                         // The union takes its field names from its first
                         // input, which may be gone. Map the remaining
                         // input's columns by position.
-                        let exprs = child
-                            .schema()
-                            .columns()
-                            .into_iter()
-                            .zip(plan.schema().iter())
-                            .map(|(col, (qualifier, field))| {
-                                Expr::Column(col)
-                                    .alias_qualified(qualifier.cloned(), 
field.name())
-                            })
-                            .collect::<Vec<_>>();
-                        Ok(Transformed::yes(LogicalPlan::Projection(
-                            Projection::try_new(exprs, Arc::new(child))?,
-                        )))
+                        Ok(Transformed::yes(align_union_input(child, 
plan.schema())?))
                     }
                 } else {
+                    // Same name mismatch as the single-input case, but the
+                    // union itself remains. Physical planning matches input
+                    // fields to these names and asserts when they differ.
+                    let inputs = new_inputs
+                        .into_iter()
+                        .map(|input| {
+                            let child = Arc::unwrap_or_clone(input);
+                            if union_input_names_match(&child, plan.schema()) {
+                                Ok(Arc::new(child))
+                            } else {
+                                align_union_input(child, 
plan.schema()).map(Arc::new)
+                            }
+                        })
+                        .collect::<Result<Vec<_>>>()?;
                     Ok(Transformed::yes(LogicalPlan::Union(Union {

Review Comment:
   Just merged https://github.com/apache/datafusion/pull/27573, which should 
also fix the issue reported in this PR.



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