Github user liancheng commented on a diff in the pull request:
https://github.com/apache/spark/pull/8200#discussion_r37081863
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
---
@@ -59,6 +59,30 @@ trait PredicateHelper {
}
}
+ /**
+ * Convert an expression into its conjunctive normal form (CNF), i.e.
AND of ORs.
+ * For example, a && b || c is normalized to (a || c) && (b || c) by
this method.
+ *
+ * Refer to https://en.wikipedia.org/wiki/Conjunctive_normal_form for
more information
+ */
+ protected def cnfNormalization(condition: Expression): Expression = {
+ condition.transformUp {
+ case or: Or => pushOrToBottom(or)
+ }
+ }
+
+ private def pushOrToBottom(condition: Expression): Expression = {
+ condition match {
+ case Or(left, right) => (left, right) match {
+ case (And(ll, lr), r) =>
+ And(pushOrToBottom(Or(ll, r)), pushOrToBottom(Or(lr, r)))
+ case (l, And(rl, rr)) =>
+ And(pushOrToBottom(Or(l, rl)), pushOrToBottom(Or(l, rr)))
+ case (l, r) => Or(l, r)
+ }
+ }
+ }
--- End diff --
Oh I see. Moving De Morgan transformation intto `BooleanSimplification`
makes sense. Please document this assumption. And you need to use
`optimizedPlan` instead of `analyzed` in your test suite.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]