v.23.10New Feature
Added arrayRandomSample SQL Function for Convenient Element Sampling
Added a new SQL function, arrayRandomSample(arr, k) which returns a sample of k elements from the input array. Similar functionality could previously be achieved only with less convenient syntax, e.g. "SELECT arrayReduce('groupArraySample(3)', range(10))". #54391 (itayisraelov).Why it matters
To provide a more straightforward and convenient way to obtain a random subset of elements from an array, simplifying what previously required more complex syntax such asarrayReduce('groupArraySample(k)', arr). This enhances query readability and ease of use for sampling array elements.How to use it
Use the function by callingarrayRandomSample(arr, k) in your SQL query, where arr is the input array and k is the number of random elements to sample. For example:SELECT arrayRandomSample([1, 2, 3, 4, 5], 3)This will return 3 random elements from the provided array.