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


##########
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:
   Yes. [ConstantFolding runs before 
BooleanSimplification](https://github.com/apache/spark/blob/ac4006aed0fde4060461f42888adcfbe03eb2321/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala#L139-L143)
 in the operator optimization batches, so `2 + 2` is folded to `Literal(4)` 
before reaching this matcher.
   I have added relevant tests. 



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