Skip to content

Commit

Permalink
Update Optimizer.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
pzzs committed May 7, 2015
1 parent 36c194e commit 35ceb7a
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 35ceb7a

Please sign in to comment.