This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new 8e428712289 [fix](in expr) fix error result when in expr has null value and lef… (#37800) 8e428712289 is described below commit 8e42871228935b241e43ed2de99cf0aa750e1774 Author: Mryange <59914473+mrya...@users.noreply.github.com> AuthorDate: Tue Jul 16 14:04:35 2024 +0800 [fix](in expr) fix error result when in expr has null value and lef… (#37800) https://github.com/apache/doris/pull/36024 ## Proposed changes ``` create table t2 (id int, c1 int); insert into t2 values(1, null); select 0 in (c1, null) from t2; -- should return null,but 1 ``` ## Proposed changes Issue Number: close #xxx <!--Describe your changes.--> --- be/src/vec/functions/in.h | 13 +++++++++--- .../data/nereids_p0/sql_functions/test_in_expr.out | 3 +++ .../nereids_p0/sql_functions/test_in_expr.groovy | 23 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/be/src/vec/functions/in.h b/be/src/vec/functions/in.h index 955f44ec491..b25ad8eeb67 100644 --- a/be/src/vec/functions/in.h +++ b/be/src/vec/functions/in.h @@ -265,8 +265,9 @@ private: continue; } - std::unique_ptr<HybridSetBase> hybrid_set( - create_set(context->get_arg_type(0)->type, set_columns.size())); + std::vector<StringRef> set_datas; + // To comply with the SQL standard, IN() returns NULL not only if the expression on the left hand side is NULL, + // but also if no match is found in the list and one of the expressions in the list is NULL. bool null_in_set = false; for (const auto& set_column : set_columns) { @@ -274,9 +275,15 @@ private: if (set_data.data == nullptr) { null_in_set = true; } else { - hybrid_set->insert((void*)(set_data.data), set_data.size); + set_datas.push_back(set_data); } } + std::unique_ptr<HybridSetBase> hybrid_set( + create_set(context->get_arg_type(0)->type, set_datas.size())); + for (auto& set_data : set_datas) { + hybrid_set->insert((void*)(set_data.data), set_data.size); + } + vec_res[i] = negative ^ hybrid_set->find((void*)ref_data.data, ref_data.size); if (null_in_set) { vec_null_map_to[i] = negative == vec_res[i]; diff --git a/regression-test/data/nereids_p0/sql_functions/test_in_expr.out b/regression-test/data/nereids_p0/sql_functions/test_in_expr.out index 31d6bb5b1ac..4881e63f223 100644 --- a/regression-test/data/nereids_p0/sql_functions/test_in_expr.out +++ b/regression-test/data/nereids_p0/sql_functions/test_in_expr.out @@ -53,3 +53,6 @@ a b d +-- !select -- +\N + diff --git a/regression-test/suites/nereids_p0/sql_functions/test_in_expr.groovy b/regression-test/suites/nereids_p0/sql_functions/test_in_expr.groovy index 8f0d3015cab..b6c1b7a7d9a 100644 --- a/regression-test/suites/nereids_p0/sql_functions/test_in_expr.groovy +++ b/regression-test/suites/nereids_p0/sql_functions/test_in_expr.groovy @@ -115,4 +115,27 @@ suite("test_in_expr", "query") { sql """DROP TABLE IF EXISTS ${nullTableName}""" sql """DROP TABLE IF EXISTS ${notNullTableName}""" + sql """DROP TABLE IF EXISTS table_with_null""" + + sql """ + CREATE TABLE IF NOT EXISTS table_with_null ( + `id` INT , + `c1` INT + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1", + "storage_format" = "V2" + ); + """ + + sql """ insert into table_with_null values(1, null); """ + + qt_select """ select 0 in (c1, null) from table_with_null;""" + + + + + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org