[feature](nereids) const folding for in-predicate with null literal (#15880)

select 1 in (2 , null)  => null
select 1 in (1 , null)  => true
select 1 not in (2 , null)  => null
select 1 not in (1 , null)  => false
This commit is contained in:
minghong
2023-01-16 13:48:45 +08:00
committed by GitHub
parent 81bab55d43
commit fa03c8a241
4 changed files with 81 additions and 0 deletions

View File

@ -328,11 +328,18 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
return inPredicate;
}
boolean hasNull = false;
for (Expression item : inPredicate.getOptions()) {
if (item.isNullLiteral()) {
hasNull = true;
}
if (valueIsLiteral && value.equals(item)) {
return BooleanLiteral.TRUE;
}
}
if (hasNull) {
return NullLiteral.INSTANCE;
}
return BooleanLiteral.FALSE;
}