sunchao commented on a change in pull request #29567:
URL: https://github.com/apache/spark/pull/29567#discussion_r479352330



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -716,6 +716,17 @@ object SimplifyCasts extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * Simplify if clauses of pattern `if(p, null, true|false)`, by replacing them 
with
+ * AND or OR clauses which are simpler and can better be pushed down
+ */
+object SimplifyIf extends Rule[LogicalPlan] {
+  val nullLiteral = Literal(null, BooleanType)
+  def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions {
+    case If(p, Literal(null, _), FalseLiteral) => And(p, nullLiteral)
+    case If(p, Literal(null, _), TrueLiteral) => Or(p, nullLiteral)

Review comment:
       How about merging these to the existing `SimplifyConditionals` as 
mentioned by @tanelk above? it will then just be a few more pattern matchings, 
right?




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