Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Safer rule
  • Loading branch information
dbtsai committed May 25, 2018
commit 6ff280616bab4f38d338b9b3aca38c4affd86cd8
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ object OptimizeIn extends Rule[LogicalPlan] {
// When v is not nullable, the following expression will be optimized
// to FalseLiteral which is tested in OptimizeInSuite.scala
If(IsNotNull(v), FalseLiteral, Literal(null, BooleanType))
case In(v, list) if list.length == 1 && !list.head.isInstanceOf[ListQuery] =>
EqualTo(v, list.head)
case In(v, Seq(elem @ Literal(_, _))) => EqualTo(v, elem)
case expr @ In(v, list) if expr.inSetConvertible =>
val newList = ExpressionSet(list).toSeq
if (newList.size > SQLConf.get.optimizerInSetConversionThreshold) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ class OptimizeInSuite extends PlanTest {
test("OptimizedIn test: one element in list gets transformed to EqualTo.") {
val originalQuery =
testRelation
.where(In(UnresolvedAttribute("a"), Seq(UnresolvedAttribute("b"))))
.where(In(UnresolvedAttribute("a"), Seq(Literal(1))))
.analyze

val optimized = Optimize.execute(originalQuery)
val correctAnswer =
testRelation
.where(EqualTo(UnresolvedAttribute("a"), UnresolvedAttribute("b")))
.where(EqualTo(UnresolvedAttribute("a"), Literal(1)))
.analyze

comparePlans(optimized, correctAnswer)
Expand Down