@@ -46,13 +46,13 @@ object DefaultOptimizer extends Optimizer {
46
46
CombineLimits ) ::
47
47
Batch (" ConstantFolding" , FixedPoint (100 ),
48
48
NullPropagation ,
49
+ OptimizeIn ,
49
50
ConstantFolding ,
50
51
LikeSimplification ,
51
52
BooleanSimplification ,
52
53
SimplifyFilters ,
53
54
SimplifyCasts ,
54
- SimplifyCaseConversionExpressions ,
55
- OptimizeIn ) ::
55
+ SimplifyCaseConversionExpressions ) ::
56
56
Batch (" Decimal Optimizations" , FixedPoint (100 ),
57
57
DecimalAggregates ) ::
58
58
Batch (" LocalRelation" , FixedPoint (100 ),
@@ -293,11 +293,19 @@ object ConstantFolding extends Rule[LogicalPlan] {
293
293
// Fold expressions that are foldable.
294
294
case e if e.foldable => Literal .create(e.eval(null ), e.dataType)
295
295
296
- // Fold "literal in (item1, item2, ..., literal, ...)" into true or false directly.
296
+ // Fold "literal in (item1, item2, ..., literal, ...)" into true or false directly when all
297
+ // elements is literal.
297
298
case InSet (Literal (v, _), hSet) => {
298
299
val isExists = hSet.contains(v)
299
300
if (isExists) Literal .create(true , BooleanType ) else Literal .create(false , BooleanType )
300
301
}
302
+
303
+ // Fold "literal in (item1, item2, ..., literal, ...)" into true directly when
304
+ // not all elements is literal.
305
+ case In (Literal (v, _), list) if list.exists {
306
+ case Literal (candidate, _) if candidate == v => true
307
+ case _ => false
308
+ } => Literal .create(true , BooleanType )
301
309
}
302
310
}
303
311
}
0 commit comments