csun5285 commented on code in PR #68438:
URL: https://github.com/apache/doris/pull/68438#discussion_r4120615865


##########
regression-test/suites/query_p0/sql_functions/array_functions/test_array_shuffle_seed.groovy:
##########
@@ -0,0 +1,99 @@
+// 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.
+
+suite("test_array_shuffle_seed") {
+    sql "DROP TABLE IF EXISTS test_array_shuffle_seed"
+    sql """
+        CREATE TABLE test_array_shuffle_seed (
+            k INT,
+            a ARRAY<INT> NULL,
+            s BIGINT NULL
+        ) DUPLICATE KEY(k)
+        DISTRIBUTED BY HASH(k) BUCKETS 1
+        PROPERTIES ("replication_num" = "1")
+    """
+    sql """
+        INSERT INTO test_array_shuffle_seed VALUES
+            (1, [1, 2, 3, 4, 5], 1),
+            (2, [1, 2, 3, 4, 5], 2),
+            (3, NULL, 1),
+            (4, [], 1),
+            (5, [42], 1)
+    """
+
+    // The rows of a block draw from one random sequence that starts from the 
seed, so a per-row
+    // seed would be ignored. A non-constant seed is rejected instead.
+    test {
+        sql "SELECT k, array_shuffle(a, s) FROM test_array_shuffle_seed"
+        exception "must be a constant"
+    }
+    test {
+        sql "SELECT k, shuffle(a, k) FROM test_array_shuffle_seed"
+        exception "must be a constant"
+    }
+    test {
+        sql """
+            WITH t AS (SELECT [1, 2, 3, 4, 5] a, 1 seed UNION ALL SELECT [1, 
2, 3, 4, 5], 2)
+            SELECT seed, array_shuffle(a, seed) FROM t ORDER BY seed
+        """
+        exception "must be a constant"
+    }
+    test {
+        sql "SELECT array_shuffle([1, 2, 3, 4, 5], cast(random() * 10 as 
bigint))"
+        exception "must be a constant"
+    }
+
+    // A constant seed gives a fixed result. A constant expression works as a 
seed too.
+    order_qt_const_seed """
+        SELECT array_shuffle([1, 2, 3, 4, 5], 1), array_shuffle([1, 2, 3, 4, 
5], 2),
+               shuffle([1, 2, 3, 4, 5], 1), array_shuffle([1, 2, 3, 4, 5], 1 + 
1)
+    """
+    // Any BIGINT is a valid seed, a negative one too. All 64 bits are used, 
so -1 and 4294967295
+    // (same low 32 bits) give different results, and so do 
-9223372036854775808 and 0.
+    order_qt_bigint_seed """
+        SELECT array_shuffle(array_range(10), -1), 
array_shuffle(array_range(10), 4294967295),
+               array_shuffle(array_range(10), -9223372036854775808),
+               array_shuffle(array_range(10), 0),
+               array_shuffle(array_range(10), 9223372036854775807)
+    """
+    // A NULL seed gives NULL.
+    order_qt_null_seed "SELECT array_shuffle([1, 2, 3, 4, 5], NULL)"
+    // Shuffling keeps the elements, so sorting them back gives a stable 
result.
+    order_qt_table """
+        SELECT k, array_sort(array_shuffle(a, 1)), array_size(shuffle(a, -1))
+        FROM test_array_shuffle_seed
+    """
+
+    // A constant array is still shuffled on each row, so the rows do not all 
get the same order.
+    order_qt_const_array """
+        SELECT count(DISTINCT cast(array_shuffle(array_range(20), 1) AS 
string)),

Review Comment:
   已修改



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to