Skip to content

Commit

Permalink
Simplify implementation of InSet.
Browse files Browse the repository at this point in the history
  • Loading branch information
marmbrus committed Nov 14, 2014
1 parent 484fecb commit 2a04ab3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ case class In(value: Expression, list: Seq[Expression]) extends Predicate {
* Optimized version of In clause, when all filter values of In clause are
* static.
*/
case class InSet(value: Expression, hset: HashSet[Any], child: Seq[Expression])
case class InSet(value: Expression, hset: Set[Any])
extends Predicate {

def children = child
def children = value :: Nil

def nullable = true // TODO: Figure out correct nullability semantics of IN.
override def toString = s"$value INSET ${hset.mkString("(", ",", ")")}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ object OptimizeIn extends Rule[LogicalPlan] {
case q: LogicalPlan => q transformExpressionsDown {
case In(v, list) if !list.exists(!_.isInstanceOf[Literal]) =>
val hSet = list.map(e => e.eval(null))
InSet(v, HashSet() ++ hSet, v +: list)
InSet(v, HashSet() ++ hSet)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ class ExpressionEvaluationSuite extends FunSuite {
val nl = Literal(null)
val s = Seq(one, two)
val nullS = Seq(one, two, null)
checkEvaluation(InSet(one, hS, one +: s), true)
checkEvaluation(InSet(two, hS, two +: s), true)
checkEvaluation(InSet(two, nS, two +: nullS), true)
checkEvaluation(InSet(nl, nS, nl +: nullS), true)
checkEvaluation(InSet(three, hS, three +: s), false)
checkEvaluation(InSet(three, nS, three +: nullS), false)
checkEvaluation(InSet(one, hS, one +: s) && InSet(two, hS, two +: s), true)
checkEvaluation(InSet(one, hS), true)
checkEvaluation(InSet(two, hS), true)
checkEvaluation(InSet(two, nS), true)
checkEvaluation(InSet(nl, nS), true)
checkEvaluation(InSet(three, hS), false)
checkEvaluation(InSet(three, nS), false)
checkEvaluation(InSet(one, hS) && InSet(two, hS), true)
}

test("MaxOf") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class OptimizeInSuite extends PlanTest {
val optimized = Optimize(originalQuery.analyze)
val correctAnswer =
testRelation
.where(InSet(UnresolvedAttribute("a"), HashSet[Any]()+1+2,
UnresolvedAttribute("a") +: Seq(Literal(1),Literal(2))))
.where(InSet(UnresolvedAttribute("a"), HashSet[Any]()+1+2))
.analyze

comparePlans(optimized, correctAnswer)
Expand Down

0 comments on commit 2a04ab3

Please sign in to comment.