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

xuyang 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 1238f6de97 [bug](array) fix be core in 
array_with_constant/array_repeat function when the first argument is nullable 
(#18404)
1238f6de97 is described below

commit 1238f6de975106869f2a2f90e70348f4fb300abc
Author: xy720 <22125576+xy...@users.noreply.github.com>
AuthorDate: Tue Apr 11 19:46:41 2023 +0800

    [bug](array) fix be core in array_with_constant/array_repeat function when 
the first argument is nullable (#18404)
    
    fix be core in array_with_constant/array_repeat function when the first 
argument is nullable
---
 be/src/vec/functions/array/function_array_with_constant.cpp   |  4 ++++
 .../sql-functions/array-functions/array_with_constant.md      |  9 +++++++++
 .../sql-functions/array-functions/array_with_constant.md      |  9 +++++++++
 .../sql_functions/array_functions/test_array_functions.out    | 11 +++++++++++
 .../array_functions/test_array_functions_by_literal.out       |  7 +++++++
 .../sql_functions/array_functions/test_array_functions.groovy |  1 +
 .../array_functions/test_array_functions_by_literal.groovy    |  2 ++
 7 files changed, 43 insertions(+)

diff --git a/be/src/vec/functions/array/function_array_with_constant.cpp 
b/be/src/vec/functions/array/function_array_with_constant.cpp
index 6c4466be55..5ee91b97a3 100644
--- a/be/src/vec/functions/array/function_array_with_constant.cpp
+++ b/be/src/vec/functions/array/function_array_with_constant.cpp
@@ -18,6 +18,7 @@
 #include "vec/columns/column_array.h"
 #include "vec/columns/column_const.h"
 #include "vec/data_types/data_type_array.h"
+#include "vec/data_types/data_type_nullable.h"
 #include "vec/data_types/data_type_number.h"
 #include "vec/functions/function.h"
 #include "vec/functions/function_helpers.h"
@@ -54,6 +55,9 @@ public:
                         size_t result, size_t input_rows_count) override {
         auto num = 
block.get_by_position(arguments[FunctionType::param_num_idx])
                            .column->convert_to_full_column_if_const();
+        num = num->is_nullable()
+                      ? assert_cast<const 
ColumnNullable*>(num.get())->get_nested_column_ptr()
+                      : num;
         auto value = 
block.get_by_position(arguments[FunctionType::param_val_idx])
                              .column->convert_to_full_column_if_const();
         auto offsets_col = ColumnVector<ColumnArray::Offset64>::create();
diff --git 
a/docs/en/docs/sql-manual/sql-functions/array-functions/array_with_constant.md 
b/docs/en/docs/sql-manual/sql-functions/array-functions/array_with_constant.md
index 9b9982c32b..60f4d0cd5e 100644
--- 
a/docs/en/docs/sql-manual/sql-functions/array-functions/array_with_constant.md
+++ 
b/docs/en/docs/sql-manual/sql-functions/array-functions/array_with_constant.md
@@ -72,6 +72,15 @@ mysql> select array_with_constant(3, null), 
array_repeat(null, 3);
 | [NULL, NULL, NULL]           |  [NULL, NULL, NULL]   |
 +------------------------------+-----------------------+
 1 row in set (0.01 sec)
+
+mysql> select array_with_constant(null, 3), array_repeat(3, null);
++------------------------------+-----------------------+
+| array_with_constant(NULL, 3) | array_repeat(3, NULL) |
++------------------------------+-----------------------+
+| []                           | []                    |
++------------------------------+-----------------------+
+1 row in set (0.01 sec)
+
 ```
 
 ### keywords
diff --git 
a/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_with_constant.md
 
b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_with_constant.md
index 99e73da2b0..bb419e6de7 100644
--- 
a/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_with_constant.md
+++ 
b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_with_constant.md
@@ -73,6 +73,15 @@ mysql> select array_with_constant(3, null), 
array_repeat(null, 3);
 | [NULL, NULL, NULL]           |  [NULL, NULL, NULL]   |
 +------------------------------+-----------------------+
 1 row in set (0.01 sec)
+
+mysql> select array_with_constant(null, 3), array_repeat(3, null);
++------------------------------+-----------------------+
+| array_with_constant(NULL, 3) | array_repeat(3, NULL) |
++------------------------------+-----------------------+
+| []                           | []                    |
++------------------------------+-----------------------+
+1 row in set (0.01 sec)
+
 ```
 
 ### keywords
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 ee258b88e9..228170dea7 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
@@ -956,6 +956,17 @@
 8      [123, 123]      [123, 123]
 9      [123, 123]      [123, 123]
 
+-- !select_array_with_constant5 --
+1      [3]     [3]
+2      [3, 3]  [3, 3]
+3      [3, 3, 3]       [3, 3, 3]
+4      [3, 3, 3, 3]    [3, 3, 3, 3]
+5      [3, 3, 3, 3, 3] [3, 3, 3, 3, 3]
+6      [3, 3, 3, 3, 3, 3]      [3, 3, 3, 3, 3, 3]
+7      [3, 3, 3, 3, 3, 3, 3]   [3, 3, 3, 3, 3, 3, 3]
+8      [3, 3, 3, 3, 3, 3, 3, 3]        [3, 3, 3, 3, 3, 3, 3, 3]
+9      [3, 3, 3, 3, 3, 3, 3, 3, 3]     [3, 3, 3, 3, 3, 3, 3, 3, 3]
+
 -- !select --
 1      [2, 1]
 2      [2, 2]
diff --git 
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out
 
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out
index 0a6df2301f..8002628352 100644
--- 
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out
+++ 
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out
@@ -617,6 +617,12 @@ _
 -- !sql_array_with_constant4 --
 [NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL]       [NULL, NULL, NULL, 
NULL, NULL, NULL, NULL, NULL]
 
+-- !sql_array_with_constant5 --
+[]     []
+
+-- !sql_array_with_constant6 --
+[]     []
+
 -- !sql --
 [1, 2, 3, NULL, 4]
 
@@ -823,3 +829,4 @@ _
 
 -- !sql --
 [333.333, 111.111, 222.222]
+
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 881704ecd4..34a791b4f2 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
@@ -139,6 +139,7 @@ suite("test_array_functions") {
     qt_select_array_with_constant2 "SELECT k1, array_with_constant(10, null), 
array_repeat(null, 10) from ${tableName} ORDER BY k1"
     qt_select_array_with_constant3 "SELECT k1, array_with_constant(2, 'a'), 
array_repeat('a', 2) from ${tableName} ORDER BY k1"
     qt_select_array_with_constant4 "SELECT k1, array_with_constant(2, 123), 
array_repeat(123, 2) from ${tableName} ORDER BY k1"
+    qt_select_array_with_constant5 "SELECT k1, array_with_constant(k1, 3), 
array_repeat(3, k1) from ${tableName} ORDER BY k1"
     qt_select "SELECT k1, array(2, k1) from ${tableName} ORDER BY k1"
     qt_select "SELECT k1, array(k1, null, '2020-01-01') from ${tableName} 
ORDER BY k1"
     qt_select "SELECT k1, array(null, k1) from ${tableName} ORDER BY k1"
diff --git 
a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy
 
b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy
index 1e9c1507ab..8d9c1487d7 100644
--- 
a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy
@@ -250,6 +250,8 @@ suite("test_array_functions_by_literal") {
     qt_sql_array_with_constant2 "select array_with_constant(2, '1'), 
array_repeat('1', 2)"
     qt_sql_array_with_constant3 "select array_with_constant(4, 1223), 
array_repeat(1223, 4)"
     qt_sql_array_with_constant4 "select array_with_constant(8, null), 
array_repeat(null, 8)"
+    qt_sql_array_with_constant5 "select array_with_constant(null, 'abc'), 
array_repeat('abc', null)"
+    qt_sql_array_with_constant6 "select array_with_constant(null, null), 
array_repeat(null, null)"
     // array_compact function
     qt_sql "select array_compact([1, 2, 3, 3, null, null, 4, 4])"
     qt_sql "select array_compact([null, null, null])"


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

Reply via email to