This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new fa03c8a241 [feature](nereids) const folding for in-predicate with null literal (#15880) fa03c8a241 is described below commit fa03c8a2418207a8fde14ab0e340b2da73123b31 Author: minghong <engle...@gmail.com> AuthorDate: Mon Jan 16 13:48:45 2023 +0800 [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 --- .../rewrite/rules/FoldConstantRuleOnFE.java | 7 +++++ .../sql/test_in_predicate_with_null.out | 31 ++++++++++++++++++++ .../test_in_predicate_with_null.out | 10 +++++++ .../sql/test_in_predicate_with_null.sql | 33 ++++++++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/rules/FoldConstantRuleOnFE.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/rules/FoldConstantRuleOnFE.java index 2ac4c7fe45..9bca83f27f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/rules/FoldConstantRuleOnFE.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rewrite/rules/FoldConstantRuleOnFE.java @@ -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; } diff --git a/regression-test/data/nereids_syntax_p0/sql/test_in_predicate_with_null.out b/regression-test/data/nereids_syntax_p0/sql/test_in_predicate_with_null.out new file mode 100644 index 0000000000..d737f26100 --- /dev/null +++ b/regression-test/data/nereids_syntax_p0/sql/test_in_predicate_with_null.out @@ -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 + diff --git a/regression-test/data/nereids_syntax_p0/test_in_predicate_with_null.out b/regression-test/data/nereids_syntax_p0/test_in_predicate_with_null.out new file mode 100644 index 0000000000..0c6e7cb080 --- /dev/null +++ b/regression-test/data/nereids_syntax_p0/test_in_predicate_with_null.out @@ -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 + diff --git a/regression-test/suites/nereids_syntax_p0/sql/test_in_predicate_with_null.sql b/regression-test/suites/nereids_syntax_p0/sql/test_in_predicate_with_null.sql new file mode 100644 index 0000000000..d0cfadd645 --- /dev/null +++ b/regression-test/suites/nereids_syntax_p0/sql/test_in_predicate_with_null.sql @@ -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); + + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org