tanelk commented on a change in pull request #27518:
URL: https://github.com/apache/spark/pull/27518#discussion_r484498520



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/QueryPlanConstraints.scala
##########
@@ -78,6 +91,72 @@ trait ConstraintHelper {
     inferredConstraints -- constraints
   }
 
+  /**
+   * Infers an additional set of constraints from a given set of inequality 
constraints.
+   * For e.g., if an operator has constraints of the form (`a > b`, `b > 5`), 
this returns an
+   * additional constraint of the form `a > 5`.
+   */
+  def inferInequalityConstraints(constraints: Set[Expression]): 
Set[Expression] = {
+    val binaryComparisons = constraints.filter {
+      case _: GreaterThan => true
+      case _: GreaterThanOrEqual => true
+      case _: LessThan => true
+      case _: LessThanOrEqual => true
+      case _: EqualTo => true
+      case _ => false
+    }
+
+    val greaterThans = binaryComparisons.map {
+      case EqualTo(l, r) if l.foldable => EqualTo(r, l)
+      case LessThan(l, r) => GreaterThan(r, l)
+      case LessThanOrEqual(l, r) => GreaterThanOrEqual(r, l)
+      case other => other
+    }
+
+    val lessThans = binaryComparisons.map {
+      case EqualTo(l, r) if l.foldable => EqualTo(r, l)
+      case GreaterThan(l, r) => LessThan(r, l)
+      case GreaterThanOrEqual(l, r) => LessThanOrEqual(r, l)
+      case other => other
+    }

Review comment:
       Is it because of tihe foldable check? Without it, it should be inferable.




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



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

Reply via email to