You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2023/04/04 00:53:22 UTC

[doris] branch master updated: [vectorized](function) Support array_shuffle and shuffle function. (#18116)

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

yiguolei 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 8b85c55117 [vectorized](function) Support array_shuffle and shuffle function. (#18116)
8b85c55117 is described below

commit 8b85c551174f24703807d3cfdd13c4d7608e2900
Author: ZhangYu0123 <67...@users.noreply.github.com>
AuthorDate: Tue Apr 4 08:53:13 2023 +0800

    [vectorized](function) Support array_shuffle and shuffle function. (#18116)
    
    
    ---------
    
    Co-authored-by: zhangyu209 <zh...@meituan.com>
---
 be/src/vec/CMakeLists.txt                          |   1 +
 .../functions/array/function_array_register.cpp    |   2 +
 .../vec/functions/array/function_array_shuffle.cpp | 101 +++++++++++++++++++++
 .../sql-functions/array-functions/array_shuffle.md |  78 ++++++++++++++++
 docs/sidebars.json                                 |   1 +
 .../sql-functions/array-functions/array_shuffle.md |  78 ++++++++++++++++
 .../apache/doris/analysis/FunctionCallExpr.java    |   4 +
 gensrc/script/doris_builtins_functions.py          |  38 ++++++++
 .../array_functions/test_array_functions.out       |  66 ++++++++++++++
 .../test_array_functions_by_literal.out            |  12 +++
 .../array_functions/test_array_functions.groovy    |   6 ++
 .../test_array_functions_by_literal.groovy         |   7 ++
 12 files changed, 394 insertions(+)

diff --git a/be/src/vec/CMakeLists.txt b/be/src/vec/CMakeLists.txt
index f4fc16147a..49cfd007e1 100644
--- a/be/src/vec/CMakeLists.txt
+++ b/be/src/vec/CMakeLists.txt
@@ -168,6 +168,7 @@ set(VEC_FILES
   functions/array/function_array_sort.cpp
   functions/array/function_array_sortby.cpp
   functions/array/function_array_utils.cpp
+  functions/array/function_array_shuffle.cpp
   functions/array/function_arrays_overlap.cpp
   functions/array/function_array_distinct.cpp
   functions/array/function_array_remove.cpp
diff --git a/be/src/vec/functions/array/function_array_register.cpp b/be/src/vec/functions/array/function_array_register.cpp
index d8ff730330..f25223ccff 100644
--- a/be/src/vec/functions/array/function_array_register.cpp
+++ b/be/src/vec/functions/array/function_array_register.cpp
@@ -22,6 +22,7 @@
 
 namespace doris::vectorized {
 
+void register_function_array_shuffle(SimpleFunctionFactory&);
 void register_function_array_exists(SimpleFunctionFactory&);
 void register_function_array_element(SimpleFunctionFactory&);
 void register_function_array_index(SimpleFunctionFactory&);
@@ -52,6 +53,7 @@ void register_function_array_pushfront(SimpleFunctionFactory& factory);
 void register_function_array_first_index(SimpleFunctionFactory& factory);
 
 void register_function_array(SimpleFunctionFactory& factory) {
+    register_function_array_shuffle(factory);
     register_function_array_exists(factory);
     register_function_array_element(factory);
     register_function_array_index(factory);
diff --git a/be/src/vec/functions/array/function_array_shuffle.cpp b/be/src/vec/functions/array/function_array_shuffle.cpp
new file mode 100644
index 0000000000..64cf845517
--- /dev/null
+++ b/be/src/vec/functions/array/function_array_shuffle.cpp
@@ -0,0 +1,101 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+#include <unistd.h>
+
+#include <random>
+
+#include "vec/columns/column_array.h"
+#include "vec/data_types/data_type_array.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/functions/function.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris::vectorized {
+
+class FunctionArrayShuffle : public IFunction {
+public:
+    static constexpr auto name = "array_shuffle";
+    static FunctionPtr create() { return std::make_shared<FunctionArrayShuffle>(); }
+
+    /// Get function name.
+    String get_name() const override { return name; }
+
+    bool is_variadic() const override { return true; }
+
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
+        DCHECK(is_array(arguments[0]))
+                << "first argument for function: " << name << " should be DataTypeArray"
+                << " and arguments[0] is " << arguments[0]->get_name();
+        return arguments[0];
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) override {
+        ColumnPtr src_column =
+                block.get_by_position(arguments[0]).column->convert_to_full_column_if_const();
+        const auto& src_column_array = assert_cast<const ColumnArray&>(*src_column);
+
+        uint32_t seed = time(nullptr);
+        if (arguments.size() == 2) {
+            ColumnPtr seed_column =
+                    block.get_by_position(arguments[1]).column->convert_to_full_column_if_const();
+            seed = seed_column->get_uint(0);
+        }
+
+        std::mt19937 g(seed);
+        auto dest_column_ptr = _execute(src_column_array, g);
+        if (!dest_column_ptr) {
+            return Status::RuntimeError(
+                    fmt::format("execute failed or unsupported types for function {}({})",
+                                get_name(), block.get_by_position(arguments[0]).type->get_name()));
+        }
+
+        block.replace_by_position(result, std::move(dest_column_ptr));
+        return Status::OK();
+    }
+
+private:
+    ColumnPtr _execute(const ColumnArray& src_column_array, std::mt19937& g) {
+        const auto& src_offsets = src_column_array.get_offsets();
+        const auto src_nested_column = src_column_array.get_data_ptr();
+
+        ColumnArray::Offset64 src_offsets_size = src_offsets.size();
+        IColumn::Permutation permutation(src_nested_column->size());
+
+        for (size_t i = 0; i < src_nested_column->size(); ++i) {
+            permutation[i] = i;
+        }
+
+        for (size_t i = 0; i < src_offsets_size; ++i) {
+            auto last_offset = src_offsets[i - 1];
+            auto src_offset = src_offsets[i];
+
+            std::shuffle(&permutation[last_offset], &permutation[src_offset], g);
+        }
+        return ColumnArray::create(src_nested_column->permute(permutation, 0),
+                                   src_column_array.get_offsets_ptr());
+    }
+};
+
+void register_function_array_shuffle(SimpleFunctionFactory& factory) {
+    factory.register_function<FunctionArrayShuffle>();
+    factory.register_alias("array_shuffle", "shuffle");
+}
+
+} // namespace doris::vectorized
\ No newline at end of file
diff --git a/docs/en/docs/sql-manual/sql-functions/array-functions/array_shuffle.md b/docs/en/docs/sql-manual/sql-functions/array-functions/array_shuffle.md
new file mode 100644
index 0000000000..53779cbd13
--- /dev/null
+++ b/docs/en/docs/sql-manual/sql-functions/array-functions/array_shuffle.md
@@ -0,0 +1,78 @@
+---
+{
+    "title": "array_shuffle",
+    "language": "en"
+}
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## array_shuffle
+
+<version since="2.0">
+
+array_shuffle(array1, [seed])
+shuffle(array1, [seed])
+
+</version>
+
+### description
+
+Randomly arrange the elements in the array. Among them, the parameter array1 is the array to be randomly arranged, and the optional parameter seed is to set the initial value used by the pseudo-random number generator to generate pseudo-random numbers.
+Shuffle has the same function as array_shuffle.
+
+```
+array_shuffle(array1);
+array_shuffle(array1, 0);
+shuffle(array1);
+shuffle(array1, 0);
+```
+
+### example
+
+```sql
+
+mysql [test]> select c_array1, array_shuffle(c_array1) from array_test; 
++-----------------------+---------------------------+
+| c_array1              | array_shuffle(`c_array1`) |
++-----------------------+---------------------------+
+| [1, 2, 3, 4, 5, NULL] | [2, NULL, 5, 3, 4, 1]     |
+| [6, 7, 8, NULL]       | [7, NULL, 8, 6]           |
+| [1, NULL]             | [1, NULL]                 |
+| NULL                  | NULL                      |
++-----------------------+---------------------------+
+4 rows in set (0.01 sec)
+
+MySQL [test]> select c_array1, array_shuffle(c_array1, 0) from array_test; 
++-----------------------+------------------------------+
+| c_array1              | array_shuffle(`c_array1`, 0) |
++-----------------------+------------------------------+
+| [1, 2, 3, 4, 5, NULL] | [1, 3, 2, NULL, 4, 5]        |
+| [6, 7, 8, NULL]       | [6, 8, 7, NULL]              |
+| [1, NULL]             | [1, NULL]                    |
+| NULL                  | NULL                         |
++-----------------------+------------------------------+
+4 rows in set (0.01 sec)
+
+```
+
+### keywords
+
+ARRAY,ARRAY_SHUFFLE,SHUFFLE
diff --git a/docs/sidebars.json b/docs/sidebars.json
index 3283ac15c3..50b1bad219 100644
--- a/docs/sidebars.json
+++ b/docs/sidebars.json
@@ -304,6 +304,7 @@
                                 "sql-manual/sql-functions/array-functions/array_compact",
                                 "sql-manual/sql-functions/array-functions/array_concat",
                                 "sql-manual/sql-functions/array-functions/array_zip",
+                                "sql-manual/sql-functions/array-functions/array_shuffle",
                                 "sql-manual/sql-functions/array-functions/array_exists",
                                 "sql-manual/sql-functions/array-functions/array_first_index",
                                 "sql-manual/sql-functions/array-functions/arrays_overlap",
diff --git a/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_shuffle.md b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_shuffle.md
new file mode 100644
index 0000000000..fc42c1fd73
--- /dev/null
+++ b/docs/zh-CN/docs/sql-manual/sql-functions/array-functions/array_shuffle.md
@@ -0,0 +1,78 @@
+---
+{
+    "title": "array_shuffle",
+    "language": "zh-CN"
+}
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+## array_shuffle
+
+<version since="2.0">
+
+array_shuffle(array1, [seed])
+shuffle(array1, [seed])
+
+</version>
+
+### description
+
+将数组中元素进行随机排列。其中,参数array1为要进行随机排列的数组,可选参数seed是设定伪随机数生成器用于生成伪随机数的初始数值。
+shuffle与array_shuffle功能相同。
+
+```
+array_shuffle(array1);
+array_shuffle(array1, 0);
+shuffle(array1);
+shuffle(array1, 0);
+```
+
+### example
+
+```sql
+
+mysql [test]> select c_array1, array_shuffle(c_array1) from array_test; 
++-----------------------+---------------------------+
+| c_array1              | array_shuffle(`c_array1`) |
++-----------------------+---------------------------+
+| [1, 2, 3, 4, 5, NULL] | [2, NULL, 5, 3, 4, 1]     |
+| [6, 7, 8, NULL]       | [7, NULL, 8, 6]           |
+| [1, NULL]             | [1, NULL]                 |
+| NULL                  | NULL                      |
++-----------------------+---------------------------+
+4 rows in set (0.01 sec)
+
+MySQL [test]> select c_array1, array_shuffle(c_array1, 0) from array_test; 
++-----------------------+------------------------------+
+| c_array1              | array_shuffle(`c_array1`, 0) |
++-----------------------+------------------------------+
+| [1, 2, 3, 4, 5, NULL] | [1, 3, 2, NULL, 4, 5]        |
+| [6, 7, 8, NULL]       | [6, 8, 7, NULL]              |
+| [1, NULL]             | [1, NULL]                    |
+| NULL                  | NULL                         |
++-----------------------+------------------------------+
+4 rows in set (0.01 sec)
+
+```
+
+### keywords
+
+ARRAY,ARRAY_SHUFFLE,SHUFFLE
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index 1edca054dd..bac630a45a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -1518,6 +1518,8 @@ public class FunctionCallExpr extends Expr {
                         || fnName.getFunction().equalsIgnoreCase("reverse")
                         || fnName.getFunction().equalsIgnoreCase("%element_slice%")
                         || fnName.getFunction().equalsIgnoreCase("array_concat")
+                        || fnName.getFunction().equalsIgnoreCase("array_shuffle")
+                        || fnName.getFunction().equalsIgnoreCase("shuffle")
                         || fnName.getFunction().equalsIgnoreCase("array_except"))
                         && ((args[ix].isDecimalV3())
                         || (children.get(0).getType().isArrayType()
@@ -1631,6 +1633,8 @@ public class FunctionCallExpr extends Expr {
                 || fnName.getFunction().equalsIgnoreCase("array_pushfront")
                 || fnName.getFunction().equalsIgnoreCase("reverse")
                 || fnName.getFunction().equalsIgnoreCase("%element_slice%")
+                || fnName.getFunction().equalsIgnoreCase("array_shuffle")
+                || fnName.getFunction().equalsIgnoreCase("shuffle")
                 || fnName.getFunction().equalsIgnoreCase("array_except")
                 || fnName.getFunction().equalsIgnoreCase("array_concat")) {
             if (children.size() > 0) {
diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py
index 23365a03a7..9d357ac8b2 100644
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -677,6 +677,44 @@ visible_functions = [
 
     [['array_first_index'], 'BIGINT', ['ARRAY_BOOLEAN'], 'ALWAYS_NOT_NULLABLE'],
 
+    [['array_shuffle', 'shuffle'], 'ARRAY_BOOLEAN',   ['ARRAY_BOOLEAN'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_TINYINT',   ['ARRAY_TINYINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_SMALLINT',  ['ARRAY_SMALLINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_INT',       ['ARRAY_INT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_BIGINT',    ['ARRAY_BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_LARGEINT',  ['ARRAY_LARGEINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DATETIME',  ['ARRAY_DATETIME'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DATE',      ['ARRAY_DATE'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DATETIMEV2',  ['ARRAY_DATETIMEV2'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DATEV2',      ['ARRAY_DATEV2'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_FLOAT',     ['ARRAY_FLOAT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DOUBLE',    ['ARRAY_DOUBLE'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DECIMALV2', ['ARRAY_DECIMALV2'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DECIMAL32', ['ARRAY_DECIMAL32'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DECIMAL64', ['ARRAY_DECIMAL64'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DECIMAL128', ['ARRAY_DECIMAL128'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_VARCHAR',   ['ARRAY_VARCHAR'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_STRING',    ['ARRAY_STRING'], ''],
+
+    [['array_shuffle', 'shuffle'], 'ARRAY_BOOLEAN',   ['ARRAY_BOOLEAN', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_TINYINT',   ['ARRAY_TINYINT', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_SMALLINT',  ['ARRAY_SMALLINT', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_INT',       ['ARRAY_INT', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_BIGINT',    ['ARRAY_BIGINT', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_LARGEINT',  ['ARRAY_LARGEINT', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DATETIME',  ['ARRAY_DATETIME', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DATE',      ['ARRAY_DATE', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DATETIMEV2',  ['ARRAY_DATETIMEV2', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DATEV2',      ['ARRAY_DATEV2', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_FLOAT',     ['ARRAY_FLOAT', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DOUBLE',    ['ARRAY_DOUBLE', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DECIMALV2', ['ARRAY_DECIMALV2', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DECIMAL32', ['ARRAY_DECIMAL32', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DECIMAL64', ['ARRAY_DECIMAL64', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_DECIMAL128', ['ARRAY_DECIMAL128', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_VARCHAR',   ['ARRAY_VARCHAR', 'BIGINT'], ''],
+    [['array_shuffle', 'shuffle'], 'ARRAY_STRING',    ['ARRAY_STRING', 'BIGINT'], ''],
+
     [['array_pushfront'], 'ARRAY_BOOLEAN',    ['ARRAY_BOOLEAN', 'BOOLEAN'], 'ALWAYS_NULLABLE'],
     [['array_pushfront'], 'ARRAY_TINYINT',    ['ARRAY_TINYINT', 'TINYINT'], 'ALWAYS_NULLABLE'],
     [['array_pushfront'], 'ARRAY_SMALLINT',   ['ARRAY_SMALLINT', 'SMALLINT'], 'ALWAYS_NULLABLE'],
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 64ca98d6f8..6f1af6a645 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
@@ -692,6 +692,72 @@
 8	\N
 9	\N
 
+-- !select_array_shuffle1 --
+1	[1, 2, 3]	6	6	[3, 2, 1]	[3, 2, 1]
+2	[4]	4	4	[4]	[4]
+3	[]	\N	\N	[]	[]
+4	[1, 2, 3, 4, 5, 4, 3, 2, 1]	25	25	[3, 2, 4, 1, 2, 4, 3, 1, 5]	[3, 2, 4, 1, 2, 4, 3, 1, 5]
+5	[]	\N	\N	[]	[]
+6	[1, 2, 3, 4, 5, 4, 3, 2, 1]	25	25	[3, 2, 4, 1, 1, 4, 5, 3, 2]	[3, 2, 4, 1, 1, 4, 5, 3, 2]
+7	[8, 9, NULL, 10, NULL]	27	27	[NULL, 9, NULL, 8, 10]	[NULL, 9, NULL, 8, 10]
+8	[1, 2, 3, 3, 4, 4, NULL]	17	17	[2, 4, 3, 4, 1, NULL, 3]	[2, 4, 3, 4, 1, NULL, 3]
+9	[1, 2, 3]	6	6	[1, 2, 3]	[1, 2, 3]
+
+-- !select_array_shuffle2 --
+1	['hi']	1	1	['hi']	['hi']
+2	['hi2']	1	1	['hi2']	['hi2']
+3	['hi3']	1	1	['hi3']	['hi3']
+4	\N	\N	\N	\N	\N
+5	\N	\N	\N	\N	\N
+6	\N	\N	\N	\N	\N
+7	\N	\N	\N	\N	\N
+8	['hi', 'hi', 'hello']	3	3	['hello', 'hi', 'hi']	['hello', 'hi', 'hi']
+9	['hi']	1	1	['hi']	['hi']
+
+-- !select_array_shuffle3 --
+1	[2015-03-13]	1	1	[2015-03-13]	[2015-03-13]
+2	\N	\N	\N	\N	\N
+3	\N	\N	\N	\N	\N
+4	\N	\N	\N	\N	\N
+5	\N	\N	\N	\N	\N
+6	\N	\N	\N	\N	\N
+7	\N	\N	\N	\N	\N
+8	[2015-03-13]	1	1	[2015-03-13]	[2015-03-13]
+9	[2015-03-13, 2015-03-13, 2015-03-14]	3	3	[2015-03-14, 2015-03-13, 2015-03-13]	[2015-03-14, 2015-03-13, 2015-03-13]
+
+-- !select_array_shuffle4 --
+1	[2015-03-13 12:36:38]	1	1	[2015-03-13 12:36:38]	[2015-03-13 12:36:38]
+2	\N	\N	\N	\N	\N
+3	\N	\N	\N	\N	\N
+4	\N	\N	\N	\N	\N
+5	\N	\N	\N	\N	\N
+6	\N	\N	\N	\N	\N
+7	\N	\N	\N	\N	\N
+8	[2015-03-13 12:36:38]	1	1	[2015-03-13 12:36:38]	[2015-03-13 12:36:38]
+9	[2015-03-13 12:36:38, 2015-03-13 12:36:38]	2	2	[2015-03-13 12:36:38, 2015-03-13 12:36:38]	[2015-03-13 12:36:38, 2015-03-13 12:36:38]
+
+-- !select_array_shuffle5 --
+1	[2022-10-15 10:30:00.999, 2022-08-31 12:00:00.999]	2	2	[2022-10-15 10:30:00.999, 2022-08-31 12:00:00.999]	[2022-10-15 10:30:00.999, 2022-08-31 12:00:00.999]
+2	[2022-11-15 10:30:00.999, 2022-01-31 12:00:00.999]	2	2	[2022-11-15 10:30:00.999, 2022-01-31 12:00:00.999]	[2022-11-15 10:30:00.999, 2022-01-31 12:00:00.999]
+3	\N	\N	\N	\N	\N
+4	\N	\N	\N	\N	\N
+5	\N	\N	\N	\N	\N
+6	\N	\N	\N	\N	\N
+7	\N	\N	\N	\N	\N
+8	\N	\N	\N	\N	\N
+9	\N	\N	\N	\N	\N
+
+-- !select_array_shuffle6 --
+1	[111.111, 222.222]	333.333	333.333	[222.222, 111.111]	[222.222, 111.111]
+2	[3333.333, 4444.444]	7777.777	7777.777	[3333.333, 4444.444]	[3333.333, 4444.444]
+3	\N	\N	\N	\N	\N
+4	\N	\N	\N	\N	\N
+5	\N	\N	\N	\N	\N
+6	\N	\N	\N	\N	\N
+7	\N	\N	\N	\N	\N
+8	\N	\N	\N	\N	\N
+9	\N	\N	\N	\N	\N
+
 -- !select --
 1	[1, 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 593071af41..bab044992c 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
@@ -689,6 +689,18 @@ _
 -- !sql --
 [2023-03-05 12:23:24.999, 2023-03-05 15:23:23.997]
 
+-- !select_array_shuffle1 --
+17	[1, 3, 2, NULL, 3, 4, NULL, 4]	[1, 3, 2, NULL, 3, 4, NULL, 4]
+
+-- !select_array_shuffle2 --
+6.666000000	[3.333, 2.222, 1.111]	[3.333, 2.222, 1.111]
+
+-- !select_array_shuffle3 --
+4	['aaa', 'bbb', NULL, 'fff']	['aaa', 'bbb', NULL, 'fff']
+
+-- !select_array_shuffle4 --
+4	['2020-01-02', '2021-01-01', '2022-01-03', '1996-04-17']	['2020-01-02', '2021-01-01', '2022-01-03', '1996-04-17']
+
 -- !sql --
 [{'a', 'd'}, {'b', 'e'}, {'c', 'f'}]
 
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 385f0e6013..d64ac9b8d3 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
@@ -115,6 +115,12 @@ suite("test_array_functions") {
     qt_select "SELECT k1, array_enumerate_uniq(k7) from ${tableName} ORDER BY k1"
     qt_select "SELECT k1, array_enumerate_uniq(k8) from ${tableName} ORDER BY k1"
     qt_select "SELECT k1, array_enumerate_uniq(k10) from ${tableName} ORDER BY k1"
+    qt_select_array_shuffle1 "SELECT k1, k2, array_sum(k2), array_sum(array_shuffle(k2)), array_shuffle(k2, 0), shuffle(k2, 0) from ${tableName} ORDER BY k1"
+    qt_select_array_shuffle2 "SELECT k1, k5, array_size(k5), array_size(array_shuffle(k5)), array_shuffle(k5, 0), shuffle(k5, 0) from ${tableName} ORDER BY k1"
+    qt_select_array_shuffle3 "SELECT k1, k6, array_size(k6), array_size(array_shuffle(k6)), array_shuffle(k6, 0), shuffle(k6, 0) from ${tableName} ORDER BY k1"
+    qt_select_array_shuffle4 "SELECT k1, k7, array_size(k7), array_size(array_shuffle(k7)), array_shuffle(k7, 0), shuffle(k7, 0) from ${tableName} ORDER BY k1"
+    qt_select_array_shuffle5 "SELECT k1, k10, array_size(k10), array_size(array_shuffle(k10)), array_shuffle(k10, 0), shuffle(k10, 0) from ${tableName} ORDER BY k1"
+    qt_select_array_shuffle6 "SELECT k1, k12, array_sum(k12), array_sum(array_shuffle(k12)), array_shuffle(k12, 1), shuffle(k12, 1) from ${tableName} ORDER BY k1"
     qt_select "SELECT k1, array_popback(k2) from ${tableName} ORDER BY k1"
     qt_select "SELECT k1, array_popback(k5) from ${tableName} ORDER BY k1"
     qt_select "SELECT k1, array_popback(k6) 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 b2044ef5b0..cbc3852ab1 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
@@ -278,6 +278,13 @@ suite("test_array_functions_by_literal") {
     qt_sql "select array_concat(array(cast (12.99 as decimal(10,3)), cast (34.99 as decimal(10,3))), array(cast (999.28 as decimal(10,3)), cast (123.99 as decimal(10,3))))"
     qt_sql "select array_concat(array(cast ('2023-03-05' as datev2), cast ('2023-03-04' as datev2)), array(cast ('2023-02-01' as datev2), cast ('2023-02-05' as datev2)))"
     qt_sql "select array_concat(array(cast ('2023-03-05 12:23:24.999' as datetimev2(3)),cast ('2023-03-05 15:23:23.997' as datetimev2(3))))"
+
+    // array_shuffle
+    qt_select_array_shuffle1 "SELECT array_sum(array_shuffle([1, 2, 3, 3, null, null, 4, 4])), array_shuffle([1, 2, 3, 3, null, null, 4, 4], 0), shuffle([1, 2, 3, 3, null, null, 4, 4], 0)"
+    qt_select_array_shuffle2 "SELECT array_sum(array_shuffle([1.111, 2.222, 3.333])), array_shuffle([1.111, 2.222, 3.333], 0), shuffle([1.111, 2.222, 3.333], 0)"
+    qt_select_array_shuffle3 "SELECT array_size(array_shuffle(['aaa', null, 'bbb', 'fff'])), array_shuffle(['aaa', null, 'bbb', 'fff'], 0), shuffle(['aaa', null, 'bbb', 'fff'], 0)"
+    qt_select_array_shuffle4 """select array_size(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17")), array_shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0), shuffle(array("2020-01-02", "2022-01-03", "2021-01-01", "1996-04-17"), 0)"""
+
     // array_zip
     qt_sql "select array_zip(['a', 'b', 'c'], ['d', 'e', 'f'])"
     qt_sql "select array_zip(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i'])"


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