kazuyukitanimura commented on a change in pull request #33930:
URL: https://github.com/apache/spark/pull/33930#discussion_r705578779
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -290,6 +290,21 @@ object OptimizeIn extends Rule[LogicalPlan] {
* 4. Removes `Not` operator.
*/
object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper {
+ // Given argument x, return true if expression Not(x) can be simplified
+ // E.g. when x == Not(y), Not(x) == Not(Not(y)) == y
+ // For the case of x = EqualTo(a, b), recursively check each child expression
+ // Extra nullable check is required for EqualNullSafe because
+ // Not(EqualNullSafe(x, null)) is different from EqualNullSafe(x, Not(null))
+ private def canSimplifyNot(x: Expression): Boolean = x match {
+ case Literal(_, BooleanType) | Literal(_, NullType) => true
+ case _: Not | _: IsNull | _: IsNotNull | _: And | _: Or => true
Review comment:
For `Not(And())` and `Not(Or())`, we have further optimization rule here
https://github.com/apache/spark/blob/f5d3984c04029bdb7f4f00ef4de25a9e9fbc75cb/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala#L452
So that we can keep pushing down `Not`
--
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]