pub fn dense_rank_int<T: Ord + Copy>(
window: IntegerAVT<'_, T>,
) -> Result<IntegerArray<i32>, KernelError>Expand description
Computes SQL DENSE_RANK() ranking for integer data with consecutive rank assignment.
Assigns consecutive rank values where tied values receive identical ranks, implementing SQL DENSE_RANK() semantics. Unlike standard ranking, eliminates gaps in rank sequence when ties occur, providing compact rank numbering for analytical applications.
§Parameters
window- Integer array view containing values for dense ranking
§Returns
Returns Result<IntegerArray<i32>, KernelError> containing:
- Success: Dense rank values with no gaps in sequence
- Error: KernelError if capacity validation fails
- Zero values for null elements
- Null mask indicating positions with valid ranks
§Dense Ranking Semantics
- DENSE_RANK() behaviour: Tied values receive same rank, next rank is consecutive
- No rank gaps: Eliminates gaps that occur in standard RANK() function
- Unique value counting: Essentially counts distinct values in sorted order
- Ascending order: Smaller integer values receive lower (better) ranks
§Comparison with RANK()
- RANK(): [1, 2, 2, 4] for values [10, 20, 20, 30]
- DENSE_RANK(): [1, 2, 2, 3] for values [10, 20, 20, 30]
§Use Cases
- Analytical queries: SQL DENSE_RANK() window function implementation
- Categorical ranking: Creating compact categorical orderings
- Percentile calculation: Foundation for percentile computations without gaps
- Data binning: Assigning data points to consecutive bins based on value
§Examples
ⓘ
use minarrow::IntegerArray;
use simd_kernels::kernels::window::dense_rank_int;
let arr = IntegerArray::<i32>::from_slice(&[10, 30, 20, 30]);
let result = dense_rank_int((&arr, 0, arr.len())).unwrap();
// Output: [1, 3, 2, 3] - dense ranking with tied values