This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push: new 0c1247f580a [fix](in expr) fix error result when in expr has null value and left expr is 0 #36024 (#36585) 0c1247f580a is described below commit 0c1247f580ac2d968632428408b45ec3b0ccd60b Author: Mryange <59914473+mrya...@users.noreply.github.com> AuthorDate: Thu Jun 20 17:54:03 2024 +0800 [fix](in expr) fix error result when in expr has null value and left expr is 0 #36024 (#36585) --- 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 18a5f86e1af..de6e72d0747 100644 --- a/be/src/vec/functions/in.h +++ b/be/src/vec/functions/in.h @@ -272,8 +272,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) { @@ -281,9 +282,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