hotienvu commented on a change in pull request #29661:
URL: https://github.com/apache/spark/pull/29661#discussion_r487359421
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -249,6 +280,10 @@ object OptimizeIn extends Rule[LogicalPlan] {
&& !v.isInstanceOf[CreateNamedStruct]
&& !newList.head.isInstanceOf[CreateNamedStruct]) {
EqualTo(v, newList.head)
+ } else if (isInteger(v) && isContinousIntegers(newList.toSet)) {
Review comment:
I've added OPTIMIZER_INSET_RANGE_CHECK_THRESHOLD (default to 20) for
this purpose
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala
##########
@@ -231,10 +231,41 @@ object ReorderAssociativeOperator extends
Rule[LogicalPlan] {
* 1. Converts the predicate to false when the list is empty and
* the value is not nullable.
* 2. Removes literal repetitions.
- * 3. Replaces [[In (value, seq[Literal])]] with optimized version
+ * 3. Replaces value IN (x,x+1,x+2..x+n) with x <= value AND value <= x + n
+ * 4. Replaces [[In (value, seq[Literal])]] with optimized version
* [[InSet (value, HashSet[Literal])]] which is much faster.
*/
object OptimizeIn extends Rule[LogicalPlan] {
+ private def isContinousIntegers(nums: Set[Expression]): Boolean = {
+ if (nums.nonEmpty && isInteger(nums.head)) {
+ val (min, max) = getBound(nums)
+ val minL = min.eval(EmptyRow).asInstanceOf[Number].longValue()
+ val maxL = max.eval(EmptyRow).asInstanceOf[Number].longValue()
+ minL + (nums.size - 1) == maxL
+ } else {
+ false
+ }
+ }
+
+ private def isInteger(v: Expression): Boolean =
+ v.dataType.isInstanceOf[ShortType] ||
Review comment:
fixed
----------------------------------------------------------------
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]