viirya commented on a change in pull request #29053:
URL: https://github.com/apache/spark/pull/29053#discussion_r452641906



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/PropagateEmptyRelation.scala
##########
@@ -50,8 +50,25 @@ object PropagateEmptyRelation extends Rule[LogicalPlan] with 
PredicateHelper wit
   override def conf: SQLConf = SQLConf.get
 
   def apply(plan: LogicalPlan): LogicalPlan = plan transformUp {
-    case p: Union if p.children.forall(isEmptyLocalRelation) =>
-      empty(p)
+    case p @ Union(children) if children.exists(isEmptyLocalRelation) =>
+      val newChildren = children.filterNot(isEmptyLocalRelation)
+      if (newChildren.isEmpty) {
+        empty(p)
+      } else {
+        val newFirstChild = if (newChildren.head eq children.head) {
+          newChildren.head
+        } else {
+          val pl = children.head.output.zip(newChildren.head.output).map {
+            case (oa, na) => Alias(na, oa.name)(oa.exprId)
+          }
+          Project(pl, newChildren.head)
+        }

Review comment:
       Looks like this may change output nullability of original Union?




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to