stevomitric commented on code in PR #58940:
URL: https://github.com/apache/spark/pull/58940#discussion_r4071528835


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -564,6 +570,70 @@ object BooleanSimplification extends Rule[LogicalPlan] 
with PredicateHelper {
 
     case _ => not
   }
+
+  private case class IntegralRange(
+      attribute: AttributeReference,
+      bound: Long,
+      isLowerBound: Boolean,
+      inclusive: Boolean)
+
+  private object IntegralComparison {
+    def unapply(expression: Expression): Option[IntegralRange] = {
+      def range(
+          attribute: AttributeReference,
+          literal: Literal,
+          isLowerBound: Boolean,
+          inclusive: Boolean): Option[IntegralRange] = {
+        if (attribute.dataType.isInstanceOf[IntegralType] &&
+            literal.dataType == attribute.dataType && literal.value != null) {
+          Some(IntegralRange(attribute, 
literal.value.asInstanceOf[Number].longValue(),
+            isLowerBound, inclusive))
+        } else {
+          None
+        }
+      }
+
+      expression match {
+        case GreaterThan(a: AttributeReference, l: Literal) => range(a, l, 
true, false)

Review Comment:
   Does constant folding run before this rule? Asking because matching against 
literal might be too restrictive, i.e. if you have an expression "2+2" which 
would be Add(Literal, Literal).



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

Reply via email to