@@ -166,29 +166,37 @@ class SimplifyConditionalSuite extends PlanTest with ExpressionEvalHelper with P
166
166
)
167
167
}
168
168
169
- test(" simplify if when then clause is null and else clause is boolean" ) {
169
+ test(" simplify if when one clause is null and another is boolean" ) {
170
170
val p = IsNull (' a )
171
171
val nullLiteral = Literal (null , BooleanType )
172
172
assertEquivalent(If (p, nullLiteral, FalseLiteral ), And (p, nullLiteral))
173
173
assertEquivalent(If (p, nullLiteral, TrueLiteral ), Or (IsNotNull (' a ), nullLiteral))
174
+ assertEquivalent(If (p, FalseLiteral , nullLiteral), And (IsNotNull (' a ), nullLiteral))
175
+ assertEquivalent(If (p, TrueLiteral , nullLiteral), Or (IsNull (' a ), nullLiteral))
174
176
175
177
// the rule should not apply to nullable predicate
176
178
Seq (TrueLiteral , FalseLiteral ).foreach { b =>
177
179
assertEquivalent(If (GreaterThan (' a , 42 ), nullLiteral, b),
178
180
If (GreaterThan (' a , 42 ), nullLiteral, b))
181
+ assertEquivalent(If (GreaterThan (' a , 42 ), b, nullLiteral),
182
+ If (GreaterThan (' a , 42 ), b, nullLiteral))
179
183
}
180
184
181
185
// check evaluation also
182
186
Seq (TrueLiteral , FalseLiteral ).foreach { b =>
183
187
checkEvaluation(If (b, nullLiteral, FalseLiteral ), And (b, nullLiteral).eval(EmptyRow ))
184
188
checkEvaluation(If (b, nullLiteral, TrueLiteral ), Or (Not (b), nullLiteral).eval(EmptyRow ))
189
+ checkEvaluation(If (b, FalseLiteral , nullLiteral), And (Not (b), nullLiteral).eval(EmptyRow ))
190
+ checkEvaluation(If (b, TrueLiteral , nullLiteral), Or (b, nullLiteral).eval(EmptyRow ))
185
191
}
186
192
187
193
// should have no effect on expressions with nullable if condition
188
194
assert((Factorial (5 ) > 100L ).nullable)
189
195
Seq (TrueLiteral , FalseLiteral ).foreach { b =>
190
196
checkEvaluation(If (Factorial (5 ) > 100L , nullLiteral, b),
191
197
If (Factorial (5 ) > 100L , nullLiteral, b).eval(EmptyRow ))
198
+ checkEvaluation(If (Factorial (5 ) > 100L , b, nullLiteral),
199
+ If (Factorial (5 ) > 100L , b, nullLiteral).eval(EmptyRow ))
192
200
}
193
201
}
194
202
}
0 commit comments