PostgreSQL `cume_dist()` — `rows_at_or_before_current_peer / partition_rows`. Peer rows (equal ORDER BY keys) share the same value, taken from the last peer's position.
(
rows: &mut [(String, serde_json::Value)],
indices: &[usize],
alias: &str,
order_by: &[(SqlExpr, bool)],
)
| 127 | /// Peer rows (equal ORDER BY keys) share the same value, taken from the last |
| 128 | /// peer's position. |
| 129 | pub(super) fn apply_cume_dist( |
| 130 | rows: &mut [(String, serde_json::Value)], |
| 131 | indices: &[usize], |
| 132 | alias: &str, |
| 133 | order_by: &[(SqlExpr, bool)], |
| 134 | ) { |
| 135 | let total = indices.len(); |
| 136 | if total == 0 { |
| 137 | return; |
| 138 | } |
| 139 | let denom = total as f64; |
| 140 | |
| 141 | let mut group_start = 0; |
| 142 | while group_start < total { |
| 143 | let mut group_end = group_start + 1; |
| 144 | while group_end < total |
| 145 | && order_keys_equal(rows, indices[group_start], indices[group_end], order_by) |
| 146 | { |
| 147 | group_end += 1; |
| 148 | } |
| 149 | let cd = group_end as f64 / denom; |
| 150 | for pos in group_start..group_end { |
| 151 | set_window_col(&mut rows[indices[pos]].1, alias, serde_json::json!(cd)); |
| 152 | } |
| 153 | group_start = group_end; |
| 154 | } |
| 155 | } |
no test coverage detected