v.23.2New Feature

Added arrayPartialSort and arrayPartialReverseSort Functions

Added arrayPartialSort and arrayPartialReverseSort functions. #46296 (Joanna Hulboj).
Added arrayPartialSort and arrayPartialReverseSort functions to ClickHouse for partial sorting of arrays in ascending and descending order respectively.

Why it matters

These functions provide efficient ways to sort only a specified number of elements within an array, improving performance and flexibility when full sorting is unnecessary. This helps users quickly access top elements without sorting entire arrays, which is valuable in data processing and optimization tasks.

How to use it

Use arrayPartialSort(array, n) to obtain the first n elements of the array sorted in ascending order, and arrayPartialReverseSort(array, n) for the first n elements sorted in descending order. Replace array with your target array column or expression and n with the number of elements to sort.