davidvrba commented on a change in pull request #27231: [SPARK-28478][SQL] 
Remove redundant null checks
URL: https://github.com/apache/spark/pull/27231#discussion_r369220530
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
 ##########
 @@ -483,6 +507,19 @@ object SimplifyConditionals extends Rule[LogicalPlan] 
with PredicateHelper {
         } else {
           e.copy(branches = branches.take(i).map(branch => (branch._1, 
elseValue)))
         }
+
+      case e @ CaseWhen(branches, elseValue) if branches.length == 1 =>
+        // remove redundant null checks for CaseWhen with one branch
+        branches(0)._1 match {
+          case IsNotNull(child) if isRedundantNullCheck(
+            elseValue.getOrElse(Literal.create(null, child.dataType)),
+            branches(0)._2, child) => branches(0)._2
+          case IsNull(child) if isRedundantNullCheck(
+            branches(0)._2,
+            elseValue.getOrElse(Literal.create(null, child.dataType)),
+            child) => elseValue.getOrElse(Literal.create(null, child.dataType))
+          case _ => e
+        }
 
 Review comment:
   Alright

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


With regards,
Apache Git Services

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

Reply via email to