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

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
 ##########
 @@ -442,6 +459,13 @@ object SimplifyConditionals extends Rule[LogicalPlan] 
with PredicateHelper {
       case If(cond, trueValue, falseValue)
         if cond.deterministic && trueValue.semanticEquals(falseValue) => 
trueValue
 
+      case i @ If(cond, trueValue, falseValue) => cond match {
+        // If the null-check is redundant, remove it
+        case IsNull(child) if isRedundantNullCheck(trueValue, falseValue, 
child) => falseValue
+        case IsNotNull(child) if isRedundantNullCheck(falseValue, trueValue, 
child) => trueValue
+        case _ => i
+      }
 
 Review comment:
   Why did you add the inner pattern-matching (`cond match {` )? I think its 
better to avoid unnecessary pattern matching (In the current fix, all the cases 
for `If` exprs can be matched in the line 466).

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


With regards,
Apache Git Services

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

Reply via email to