Skip to content

Commit 0f61953

Browse files
committed
Update doc and add one more test case
1 parent 03c522e commit 0f61953

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RewriteArithmeticFiltersOnIntOrLongColumn.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ import org.apache.spark.sql.types.{DataType, IntegerType, LongType}
3838
* {{{
3939
* SELECT * FROM table WHERE i = 2
4040
* }}}
41+
* The arithmetic operation supports `Add` and `Subtract`. The comparision supports
42+
* '=', '>=', '<=', '>', '<', '!='. It only supports type of `INT` and `LONG`,
43+
* it doesn't support `FLOAT` or `DOUBLE` for precision issues.
4144
*/
4245
object RewriteArithmeticFiltersOnIntOrLongColumn extends Rule[LogicalPlan] with PredicateHelper {
4346
def apply(plan: LogicalPlan): LogicalPlan = plan transform {

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/optimizer/RewriteArithmeticFiltersOnIntOrLongColumnSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,15 @@ class RewriteArithmeticFiltersOnIntOrLongColumnSuite extends PlanTest {
240240

241241
comparePlans(Optimize.execute(query.analyze), correctAnswer)
242242
}
243+
244+
test("test of int: 2 - a != 8") {
245+
val query = testRelation
246+
.where(Subtract(Literal(2), columnA) != Literal(8))
247+
248+
val correctAnswer = testRelation
249+
.where(Literal(-6) != columnA)
250+
.analyze
251+
252+
comparePlans(Optimize.execute(query.analyze), correctAnswer)
253+
}
243254
}

0 commit comments

Comments
 (0)