@@ -40,25 +40,26 @@ import org.apache.spark.sql.types._
40
40
*
41
41
* Note:
42
42
* 1. This rule supports `Add` and `Subtract` in arithmetic expressions.
43
- * 2. This rule supports `=`, `>=`, `<=`, `>`, `<`, and `!=` in comparators.
43
+ * 2. This rule supports `=` and `!=` in comparators. For `>`, `>=`, `<`, `<=`,
44
+ * it may brings inconsistencies after rewrite.
44
45
* 3. This rule supports integral-type (`byte`, `short`, `int`, `long`) only.
45
46
* It doesn't support `float` or `double` because of precision issues.
46
47
*/
47
48
object RewriteArithmeticFiltersOnIntegralColumn extends Rule [LogicalPlan ] with PredicateHelper {
48
49
def apply (plan : LogicalPlan ): LogicalPlan = plan transform {
49
50
case f : Filter =>
50
51
f transformExpressionsUp {
51
- case e @ BinaryComparison (left : BinaryArithmetic , right : Expression )
52
+ case e @ EqualTo (left : BinaryArithmetic , right : Expression )
52
53
if right.foldable && isDataTypeSafe(left.dataType) =>
53
54
transformLeft(e, left, right)
54
- case e @ BinaryComparison (left : Expression , right : BinaryArithmetic )
55
+ case e @ EqualTo (left : Expression , right : BinaryArithmetic )
55
56
if left.foldable && isDataTypeSafe(right.dataType) =>
56
57
transformRight(e, left, right)
57
58
}
58
59
}
59
60
60
61
private def transformLeft (
61
- bc : BinaryComparison ,
62
+ bc : EqualTo ,
62
63
left : BinaryArithmetic ,
63
64
right : Expression ): Expression = {
64
65
left match {
@@ -75,7 +76,7 @@ object RewriteArithmeticFiltersOnIntegralColumn extends Rule[LogicalPlan] with P
75
76
}
76
77
77
78
private def transformRight (
78
- bc : BinaryComparison ,
79
+ bc : EqualTo ,
79
80
left : Expression ,
80
81
right : BinaryArithmetic ): Expression = {
81
82
right match {
0 commit comments