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 0c9d20c17cf [fix](array) fix array_except/union for left const return 
only one row result #36776 (#36934)
0c9d20c17cf is described below

commit 0c9d20c17cf79a5683fde41e636d9bac50a7fe37
Author: amory <wangqian...@selectdb.com>
AuthorDate: Tue Jul 2 15:36:25 2024 +0800

    [fix](array) fix array_except/union for left const return only one row 
result #36776 (#36934)
---
 be/src/vec/functions/array/function_array_set.h              |  7 ++++++-
 .../sql_functions/array_functions/test_array_functions.out   | 12 ++++++++++++
 .../array_functions/test_array_functions.groovy              |  3 +++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/be/src/vec/functions/array/function_array_set.h 
b/be/src/vec/functions/array/function_array_set.h
index 41bf53f921f..e28835d38ed 100644
--- a/be/src/vec/functions/array/function_array_set.h
+++ b/be/src/vec/functions/array/function_array_set.h
@@ -181,7 +181,12 @@ private:
         constexpr auto execute_left_column_first = 
Impl::Action::execute_left_column_first;
         size_t current = 0;
         Impl impl;
-        for (size_t row = 0; row < left_data.offsets_ptr->size(); ++row) {
+        size_t row_size = left_data.offsets_ptr->size();
+        if constexpr (LCONST) {
+            // if left param is const column, we should use right data offset 
to get truely row_size
+            row_size = right_data.offsets_ptr->size();
+        }
+        for (size_t row = 0; row < row_size; ++row) {
             size_t count = 0;
             size_t left_off = (*left_data.offsets_ptr)[index_check_const(row, 
LCONST) - 1];
             size_t left_len = (*left_data.offsets_ptr)[index_check_const(row, 
LCONST)] - left_off;
diff --git 
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out
 
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out
index 1b60f427058..664ea154982 100644
--- 
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out
+++ 
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions.out
@@ -1659,14 +1659,26 @@
 10005  [10005, null, null]     [null, 3, 10005, 2, 1]
 10006  [60002, 60002, 60003, null, 60005]      [null, 3, 60002, 60005, 60003, 
2, 1]
 
+-- !select_union_left_const --
+10005  [10005, null, null]     [null, 3, 10005, 2, 1]
+10006  [60002, 60002, 60003, null, 60005]      [null, 3, 60002, 60005, 60003, 
2, 1]
+
 -- !select_except --
 10005  [10005, null, null]     [10005, null]
 10006  [60002, 60002, 60003, null, 60005]      [60002, 60003, null, 60005]
 
+-- !select_except_left_const --
+10005  [10005, null, null]     [1, 2, 3]
+10006  [60002, 60002, 60003, null, 60005]      [1, 2, 3]
+
 -- !select_intersect --
 10005  [10005, null, null]     [null]
 10006  [60002, 60002, 60003, null, 60005]      [null]
 
+-- !select_intersect_left_const --
+10005  [10005, null, null]     [null]
+10006  [60002, 60002, 60003, null, 60005]      [null]
+
 -- !select_array_datetimev2_1 --
 1      ["2023-01-19 18:11:11.111", "2023-01-19 18:22:22.222", "2023-01-19 
18:33:33.333"]       ["2023-01-19 18:22:22.222", "2023-01-19 18:33:33.333", 
"2023-01-19 18:44:44.444"]       ["2023-01-19 18:11:11.111111", "2023-01-19 
18:22:22.222222", "2023-01-19 18:33:33.333333"]
 
diff --git 
a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy
 
b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy
index c043ada07af..f278483e707 100644
--- 
a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions.groovy
@@ -273,8 +273,11 @@ suite("test_array_functions") {
     sql """ insert into ${tableName3} values 
(10006,'bbbbb',[60002,60002,60003,null,60005]) """
     
     qt_select_union "select class_id, student_ids, 
array_union(student_ids,[1,2,3]) from ${tableName3} order by class_id;"
+    qt_select_union_left_const "select class_id, student_ids, 
array_union([1,2,3], student_ids,[1,2,3]) from ${tableName3} order by class_id;"
     qt_select_except "select class_id, student_ids, 
array_except(student_ids,[1,2,3]) from ${tableName3} order by class_id;"
+    qt_select_except_left_const "select class_id, student_ids, 
array_except([1,2,3], student_ids) from ${tableName3} order by class_id;"
     qt_select_intersect "select class_id, student_ids, 
array_intersect(student_ids,[1,2,3,null]) from ${tableName3} order by class_id;"
+    qt_select_intersect_left_const "select class_id, student_ids, 
array_intersect([1,2,3,null], student_ids) from ${tableName3} order by 
class_id;"
 
     def tableName4 = "tbl_test_array_datetimev2_functions"
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to