From 35ceb7aa66243b984414e66342563d45823c7b46 Mon Sep 17 00:00:00 2001 From: Zhongshuai Pei <799203320@qq.com> Date: Thu, 7 May 2015 19:10:14 +0800 Subject: [PATCH] Update Optimizer.scala --- .../spark/sql/catalyst/optimizer/Optimizer.scala | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala index 6dc08606ee704..604821227e0ff 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala @@ -46,13 +46,13 @@ object DefaultOptimizer extends Optimizer { CombineLimits) :: Batch("ConstantFolding", FixedPoint(100), NullPropagation, + OptimizeIn, ConstantFolding, LikeSimplification, BooleanSimplification, SimplifyFilters, SimplifyCasts, - SimplifyCaseConversionExpressions, - OptimizeIn) :: + SimplifyCaseConversionExpressions) :: Batch("Decimal Optimizations", FixedPoint(100), DecimalAggregates) :: Batch("LocalRelation", FixedPoint(100), @@ -293,11 +293,19 @@ object ConstantFolding extends Rule[LogicalPlan] { // Fold expressions that are foldable. case e if e.foldable => Literal.create(e.eval(null), e.dataType) - // Fold "literal in (item1, item2, ..., literal, ...)" into true or false directly. + // Fold "literal in (item1, item2, ..., literal, ...)" into true or false directly when all + // elements is literal. case InSet(Literal(v, _), hSet) => { val isExists = hSet.contains(v) if(isExists) Literal.create(true, BooleanType) else Literal.create(false, BooleanType) } + + // Fold "literal in (item1, item2, ..., literal, ...)" into true directly when + // not all elements is literal. + case In(Literal(v, _), list) if list.exists { + case Literal(candidate, _) if candidate == v => true + case _ => false + } => Literal.create(true, BooleanType) } } }