ulysses-you commented on a change in pull request #35135:
URL: https://github.com/apache/spark/pull/35135#discussion_r780783287
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/PropagateEmptyRelation.scala
##########
@@ -59,6 +62,27 @@ abstract class PropagateEmptyRelationBase extends
Rule[LogicalPlan] with CastSup
plan.output.map{ a => Alias(cast(Literal(null), a.dataType),
a.name)(a.exprId) }
protected def commonApplyFunc: PartialFunction[LogicalPlan, LogicalPlan] = {
+ case p: Union if p.children.exists(isEmpty) =>
+ val newChildren = p.children.filterNot(isEmpty)
+ if (newChildren.isEmpty) {
+ empty(p)
+ } else {
+ val newPlan = if (newChildren.size > 1) Union(newChildren) else
newChildren.head
+ val outputs = newPlan.output.zip(p.output)
+ // the original Union may produce different output attributes than the
new one so we alias
+ // them if needed
+ if (outputs.forall { case (newAttr, oldAttr) => newAttr.exprId ==
oldAttr.exprId }) {
+ newPlan
+ } else {
+ val outputAliases = outputs.map { case (newAttr, oldAttr) =>
+ val newExplicitMetadata =
+ if (oldAttr.metadata != newAttr.metadata) Some(oldAttr.metadata)
else None
+ Alias(newAttr, oldAttr.name)(explicitMetadata =
newExplicitMetadata)
Review comment:
A small bug fix, the previous is
`Alias(newAttr, oldAttr.name)(oldAttr.exprId, explicitMetadata =
newExplicitMetadata)`
We should make alias use the not same expr id with references as the
integral check do `LogicalPlanIntegrity.checkIfExprIdsAreGloballyUnique`.
--
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]