v.23.11New Feature
Added arrayRandomSample SQL Function for Simplified 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)). #56416 (Robert Schulze).
Why it matters
This feature simplifies extracting a random subset of elements from an array, replacing the previously more complex and less convenient syntax usingarrayReduce('groupArraySample(k)', ...). It improves usability and readability for users needing to sample array data.How to use it
Use the function by callingarrayRandomSample(arr, k), 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)returns three random elements from the given array.