Skip to content

Commit 2a04ab3

Browse files
committed
Simplify implementation of InSet.
1 parent 484fecb commit 2a04ab3

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ case class In(value: Expression, list: Seq[Expression]) extends Predicate {
9999
* Optimized version of In clause, when all filter values of In clause are
100100
* static.
101101
*/
102-
case class InSet(value: Expression, hset: HashSet[Any], child: Seq[Expression])
102+
case class InSet(value: Expression, hset: Set[Any])
103103
extends Predicate {
104104

105-
def children = child
105+
def children = value :: Nil
106106

107107
def nullable = true // TODO: Figure out correct nullability semantics of IN.
108108
override def toString = s"$value INSET ${hset.mkString("(", ",", ")")}"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ object OptimizeIn extends Rule[LogicalPlan] {
289289
case q: LogicalPlan => q transformExpressionsDown {
290290
case In(v, list) if !list.exists(!_.isInstanceOf[Literal]) =>
291291
val hSet = list.map(e => e.eval(null))
292-
InSet(v, HashSet() ++ hSet, v +: list)
292+
InSet(v, HashSet() ++ hSet)
293293
}
294294
}
295295
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ class ExpressionEvaluationSuite extends FunSuite {
158158
val nl = Literal(null)
159159
val s = Seq(one, two)
160160
val nullS = Seq(one, two, null)
161-
checkEvaluation(InSet(one, hS, one +: s), true)
162-
checkEvaluation(InSet(two, hS, two +: s), true)
163-
checkEvaluation(InSet(two, nS, two +: nullS), true)
164-
checkEvaluation(InSet(nl, nS, nl +: nullS), true)
165-
checkEvaluation(InSet(three, hS, three +: s), false)
166-
checkEvaluation(InSet(three, nS, three +: nullS), false)
167-
checkEvaluation(InSet(one, hS, one +: s) && InSet(two, hS, two +: s), true)
161+
checkEvaluation(InSet(one, hS), true)
162+
checkEvaluation(InSet(two, hS), true)
163+
checkEvaluation(InSet(two, nS), true)
164+
checkEvaluation(InSet(nl, nS), true)
165+
checkEvaluation(InSet(three, hS), false)
166+
checkEvaluation(InSet(three, nS), false)
167+
checkEvaluation(InSet(one, hS) && InSet(two, hS), true)
168168
}
169169

170170
test("MaxOf") {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ class OptimizeInSuite extends PlanTest {
5252
val optimized = Optimize(originalQuery.analyze)
5353
val correctAnswer =
5454
testRelation
55-
.where(InSet(UnresolvedAttribute("a"), HashSet[Any]()+1+2,
56-
UnresolvedAttribute("a") +: Seq(Literal(1),Literal(2))))
55+
.where(InSet(UnresolvedAttribute("a"), HashSet[Any]()+1+2))
5756
.analyze
5857

5958
comparePlans(optimized, correctAnswer)

0 commit comments

Comments
 (0)