cloud-fan commented on a change in pull request #30852:
URL: https://github.com/apache/spark/pull/30852#discussion_r547133578



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/ReplaceNullWithFalseInPredicate.scala
##########
@@ -94,6 +94,7 @@ object ReplaceNullWithFalseInPredicate extends 
Rule[LogicalPlan] {
         replaceNullWithFalse(cond) -> replaceNullWithFalse(value)
       }
       val newElseValue = cw.elseValue.map(replaceNullWithFalse)
+        .orElse(if (newBranches.forall(_._2 == FalseLiteral)) 
Some(FalseLiteral) else None)

Review comment:
       I didn't mean we should blindly fill the ELSE branch with null literal. 
We can virtually treat unspecified ELSE as null literal, to enhance the logic 
in `SimplifyConditionals` and `ReplaceNullWithFalseInPredicate`.
   
   For example, `SimplifyConditionals` can do something like
   ```
   case e @ CaseWhen(branches, elseOpt)
       if branches.forall(_._2.semanticEquals(elseOpt.getOrElse(Literal(null, 
e.dataType)))) =>
     ...
   ```
   It won't change the expression if there is no benefit.




----------------------------------------------------------------
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to