This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 19621d40cd8 branch-3.1: [fix](function) Crash caused by explode 
function #56991 (#57002)
19621d40cd8 is described below

commit 19621d40cd8961eba5303063028537a6873e2367
Author: Jerry Hu <[email protected]>
AuthorDate: Thu Oct 16 10:34:41 2025 +0800

    branch-3.1: [fix](function) Crash caused by explode function #56991 (#57002)
    
    pick #56991
---
 be/src/vec/exprs/table_function/vexplode_v2.cpp    | 23 +++----
 .../sql_functions/table_function/explode.out       | 72 ++++++++++++++++++++++
 .../sql_functions/table_function/explode.groovy    | 25 ++++++++
 3 files changed, 109 insertions(+), 11 deletions(-)

diff --git a/be/src/vec/exprs/table_function/vexplode_v2.cpp 
b/be/src/vec/exprs/table_function/vexplode_v2.cpp
index 44659dde806..02864c58115 100644
--- a/be/src/vec/exprs/table_function/vexplode_v2.cpp
+++ b/be/src/vec/exprs/table_function/vexplode_v2.cpp
@@ -218,21 +218,22 @@ int VExplodeV2TableFunction::get_value(MutableColumnPtr& 
column, int max_step) {
                     } else {
                         nullmap_column->insert_many_defaults(max_step);
                     }
-                } else {
+                } else if (element_size > _cur_offset) {
+                    const auto current_insert_num = element_size - _cur_offset;
                     
nullable_column->get_nested_column_ptr()->insert_range_from(
-                            *detail.nested_col, pos, element_size - 
_cur_offset);
+                            *detail.nested_col, pos, current_insert_num);
                     if (detail.nested_nullmap_data) {
-                        for (int j = 0; j < element_size - _cur_offset; j++) {
-                            if (detail.nested_nullmap_data[pos + j]) {
-                                nullmap_column->insert_value(1);
-                            } else {
-                                nullmap_column->insert_value(0);
-                            }
-                        }
+                        const auto old_size = nullmap_column->size();
+                        nullmap_column->resize(old_size + current_insert_num);
+                        memcpy(nullmap_column->get_data().data() + old_size,
+                               detail.nested_nullmap_data + pos,
+                               current_insert_num * sizeof(UInt8));
                     } else {
-                        nullmap_column->insert_many_defaults(element_size - 
_cur_offset);
+                        
nullmap_column->insert_many_defaults(current_insert_num);
                     }
-                    nullable_column->insert_many_defaults(max_step - 
(element_size - _cur_offset));
+                    nullable_column->insert_many_defaults(max_step - 
current_insert_num);
+                } else {
+                    nullable_column->insert_many_defaults(max_step);
                 }
             }
         }
diff --git 
a/regression-test/data/query_p0/sql_functions/table_function/explode.out 
b/regression-test/data/query_p0/sql_functions/table_function/explode.out
index 234119bea63..1a6280bb84f 100644
--- a/regression-test/data/query_p0/sql_functions/table_function/explode.out
+++ b/regression-test/data/query_p0/sql_functions/table_function/explode.out
@@ -675,3 +675,75 @@
 3      116     \N      115     \N
 3      116     \N      116     \N
 
+-- !test24 --
+a      \N      \N      \N      4
+a      \N      \N      \N      5
+a      \N      \N      ef      1
+a      \N      1       ab      \N
+a      \N      2       cd      \N
+a      \N      4       \N      2
+a      \N      5       \N      3
+b      \N      \N      \N      4
+b      \N      \N      \N      5
+b      \N      \N      ef      1
+b      \N      1       ab      \N
+b      \N      2       cd      \N
+b      \N      4       \N      2
+b      \N      5       \N      3
+c      \N      \N      \N      4
+c      \N      \N      \N      5
+c      \N      \N      ef      1
+c      \N      1       ab      \N
+c      \N      2       cd      \N
+c      \N      4       \N      2
+c      \N      5       \N      3
+d      \N      \N      \N      4
+d      \N      \N      \N      5
+d      \N      \N      ef      1
+d      \N      1       ab      \N
+d      \N      2       cd      \N
+d      \N      4       \N      2
+d      \N      5       \N      3
+e      \N      \N      \N      4
+e      \N      \N      \N      5
+e      \N      \N      ef      1
+e      \N      1       ab      \N
+e      \N      2       cd      \N
+e      \N      4       \N      2
+e      \N      5       \N      3
+f      \N      \N      \N      4
+f      \N      \N      \N      5
+f      \N      \N      ef      1
+f      \N      1       ab      \N
+f      \N      2       cd      \N
+f      \N      4       \N      2
+f      \N      5       \N      3
+g      \N      \N      \N      4
+g      \N      \N      \N      5
+g      \N      \N      ef      1
+g      \N      1       ab      \N
+g      \N      2       cd      \N
+g      \N      4       \N      2
+g      \N      5       \N      3
+h      \N      \N      \N      4
+h      \N      \N      \N      5
+h      \N      \N      ef      1
+h      \N      1       ab      \N
+h      \N      2       cd      \N
+h      \N      4       \N      2
+h      \N      5       \N      3
+i      \N      \N      \N      4
+i      \N      \N      \N      5
+i      \N      \N      ef      1
+i      \N      1       ab      \N
+i      \N      2       cd      \N
+i      \N      4       \N      2
+i      \N      5       \N      3
+j      \N      \N      \N      4
+j      \N      \N      \N      5
+j      \N      \N      ef      1
+j      \N      1       ab      \N
+j      \N      2       cd      \N
+j      \N      4       \N      2
+j      \N      5       \N      3
+
diff --git 
a/regression-test/suites/query_p0/sql_functions/table_function/explode.groovy 
b/regression-test/suites/query_p0/sql_functions/table_function/explode.groovy
index 76d79705704..88f7a85023f 100644
--- 
a/regression-test/suites/query_p0/sql_functions/table_function/explode.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/table_function/explode.groovy
@@ -189,4 +189,29 @@ suite("explode") {
     qt_test22 "select id,e1,e2,e3 from array_test as a lateral view 
explode_variant_array(a.v_string['a'],a.v_int['a'],a.v_int['a']) tmp1 as 
e1,e2,e3;"
     qt_test23 "select id,e1,e2,e11,e12 from array_test as a lateral view 
explode_variant_array(a.v_int['a'],a.v_string['a']) tmp1 as e1,e2 lateral view 
explode_variant_array(a.v_int['a'],a.v_string['a']) tmp2 as e11,e12;"
 
+    sql "DROP TABLE IF EXISTS array_test2;"
+    sql """
+        CREATE TABLE `array_test2` (
+        `v` varchar(10)
+        ) DISTRIBUTED BY RANDOM BUCKETS 1
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1"
+        );
+    """
+
+    sql """
+        insert into array_test2 values
+            ("a"), ("b"), ("c"), ("d"), ("e"),
+            ("f"), ("g"), ("h"), ("i"), ("j");
+    """
+
+    sql "set batch_size = 16"
+
+    qt_test24 """
+        select
+            *
+        from array_test2 
+        lateral view explode([], [1, 2, null, 4, 5], ["ab", "cd", "ef"], 
[null, null, 1, 2, 3, 4, 5]) t2 as c0, c1, c2, c3 
+        order by 1,2,3,4,5;
+    """
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to