Skip to content

Commit

Permalink
[SPARK-4468][SQL] Fixes Parquet filter creation for inequality predic…
Browse files Browse the repository at this point in the history
…ates with literals on the left hand side

For expressions like `10 < someVar`, we should create an `Operators.Gt` filter, but right now an `Operators.Lt` is created. This issue affects all inequality predicates with literals on the left hand side.

(This bug existed before #3317 and affects branch-1.1. #3338 was opened to backport this to branch-1.1.)

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/apache/spark/3334)
<!-- Reviewable:end -->

Author: Cheng Lian <[email protected]>

Closes #3334 from liancheng/fix-parquet-comp-filter and squashes the following commits:

0130897 [Cheng Lian] Fixes Parquet comparison filter generation
  • Loading branch information
liancheng authored and marmbrus committed Nov 19, 2014
1 parent 7f22fa8 commit 423baea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,22 @@ private[sql] object ParquetFilters {
case LessThan(NamedExpression(name, _), Literal(value, dataType)) =>
makeLt.lift(dataType).map(_(name, value))
case LessThan(Literal(value, dataType), NamedExpression(name, _)) =>
makeLt.lift(dataType).map(_(name, value))
makeGt.lift(dataType).map(_(name, value))

case LessThanOrEqual(NamedExpression(name, _), Literal(value, dataType)) =>
makeLtEq.lift(dataType).map(_(name, value))
case LessThanOrEqual(Literal(value, dataType), NamedExpression(name, _)) =>
makeLtEq.lift(dataType).map(_(name, value))
makeGtEq.lift(dataType).map(_(name, value))

case GreaterThan(NamedExpression(name, _), Literal(value, dataType)) =>
makeGt.lift(dataType).map(_(name, value))
case GreaterThan(Literal(value, dataType), NamedExpression(name, _)) =>
makeGt.lift(dataType).map(_(name, value))
makeLt.lift(dataType).map(_(name, value))

case GreaterThanOrEqual(NamedExpression(name, _), Literal(value, dataType)) =>
makeGtEq.lift(dataType).map(_(name, value))
case GreaterThanOrEqual(Literal(value, dataType), NamedExpression(name, _)) =>
makeGtEq.lift(dataType).map(_(name, value))
makeLtEq.lift(dataType).map(_(name, value))

case And(lhs, rhs) =>
(createFilter(lhs) ++ createFilter(rhs)).reduceOption(FilterApi.and)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,21 @@ class ParquetQuerySuite extends QueryTest with FunSuiteLike with BeforeAndAfterA
}

checkFilter[Operators.Eq[Integer]]('a.int === 1)
checkFilter[Operators.Eq[Integer]](Literal(1) === 'a.int)

checkFilter[Operators.Lt[Integer]]('a.int < 4)
checkFilter[Operators.Lt[Integer]](Literal(4) > 'a.int)
checkFilter[Operators.LtEq[Integer]]('a.int <= 4)
checkFilter[Operators.LtEq[Integer]](Literal(4) >= 'a.int)

checkFilter[Operators.Gt[Integer]]('a.int > 4)
checkFilter[Operators.Gt[Integer]](Literal(4) < 'a.int)
checkFilter[Operators.GtEq[Integer]]('a.int >= 4)
checkFilter[Operators.GtEq[Integer]](Literal(4) <= 'a.int)

checkFilter[Operators.And]('a.int === 1 && 'a.int < 4)
checkFilter[Operators.Or]('a.int === 1 || 'a.int < 4)
checkFilter[Operators.Not](!('a.int === 1))

checkFilter('a.int > 'b.int, defined = false)
checkFilter(('a.int > 'b.int) && ('a.int > 'b.int), defined = false)
Expand Down

0 comments on commit 423baea

Please sign in to comment.