[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:
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
-- This file is automatically generated. You should know what you did if you want to edit this
|
||||
-- !test_in_predicate_with_null --
|
||||
0
|
||||
|
||||
-- !test_in_predicate_with_null_2 --
|
||||
0
|
||||
|
||||
-- !test_in_predicate_with_null_3 --
|
||||
true
|
||||
|
||||
-- !test_in_predicate_with_null_4 --
|
||||
\N
|
||||
|
||||
-- !test_in_predicate_with_null_5 --
|
||||
false
|
||||
|
||||
-- !test_in_predicate_with_null_6 --
|
||||
\N
|
||||
|
||||
-- !test_in_predicate_with_null_7 --
|
||||
true
|
||||
|
||||
-- !test_in_predicate_with_null_8 --
|
||||
\N
|
||||
|
||||
-- !test_in_predicate_with_null_9 --
|
||||
false
|
||||
|
||||
-- !test_in_predicate_with_null_10 --
|
||||
\N
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
-- This file is automatically generated. You should know what you did if you want to edit this
|
||||
-- !select --
|
||||
\N
|
||||
|
||||
-- !select --
|
||||
1
|
||||
|
||||
-- !select --
|
||||
2 4
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
-- Licensed to the Apache Software Foundation (ASF) under one
|
||||
-- or more contributor license agreements. See the NOTICE file
|
||||
-- distributed with this work for additional information
|
||||
-- regarding copyright ownership. The ASF licenses this file
|
||||
-- to you under the Apache License, Version 2.0 (the
|
||||
-- "License"); you may not use this file except in compliance
|
||||
-- with the License. You may obtain a copy of the License at
|
||||
--
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
--
|
||||
-- Unless required by applicable law or agreed to in writing,
|
||||
-- software distributed under the License is distributed on an
|
||||
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
-- KIND, either express or implied. See the License for the
|
||||
-- specific language governing permissions and limitations
|
||||
-- under the License.
|
||||
|
||||
SET enable_nereids_planner=true;
|
||||
SET enable_fallback_to_original_planner=false;
|
||||
|
||||
select 1 in (1, null);
|
||||
select 1 in (2, null);
|
||||
|
||||
select 1 not in (1, null);
|
||||
select 1 not in (2, null);
|
||||
|
||||
select 1 in (2, null, 1);
|
||||
select 1 in (null, 2);
|
||||
|
||||
select 1 not in (null, 1);
|
||||
select 1 not in (null, 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user