Evaluate window functions over a `Vec >` result set. `column_index` maps column name → position in each row slice. For each spec, one `Value` is appended to every row. Returns the list of new column names, one per spec in spec order.
(
rows: &mut [Vec<Value>],
column_index: &HashMap<String, usize>,
specs: &[WindowFuncSpec],
)
| 34 | /// For each spec, one `Value` is appended to every row. Returns the list of |
| 35 | /// new column names, one per spec in spec order. |
| 36 | pub fn evaluate_window_functions_value( |
| 37 | rows: &mut [Vec<Value>], |
| 38 | column_index: &HashMap<String, usize>, |
| 39 | specs: &[WindowFuncSpec], |
| 40 | ) -> Result<Vec<String>, WindowError> { |
| 41 | let mut new_cols: Vec<String> = Vec::with_capacity(specs.len()); |
| 42 | |
| 43 | for spec in specs { |
| 44 | let partitions = build_value_partitions(rows, column_index, spec)?; |
| 45 | let write_col = rows.first().map(|r| r.len()).unwrap_or(0); |
| 46 | |
| 47 | for row in rows.iter_mut() { |
| 48 | row.push(Value::Null); |
| 49 | } |
| 50 | |
| 51 | for partition_indices in &partitions { |
| 52 | match spec.func_name.as_str() { |
| 53 | "row_number" => apply_v_row_number(rows, partition_indices, write_col), |
| 54 | "rank" => apply_v_rank(rows, partition_indices, column_index, spec, write_col), |
| 55 | "dense_rank" => { |
| 56 | apply_v_dense_rank(rows, partition_indices, column_index, spec, write_col) |
| 57 | } |
| 58 | "ntile" => apply_v_ntile(rows, partition_indices, spec, write_col)?, |
| 59 | "percent_rank" => { |
| 60 | apply_v_percent_rank(rows, partition_indices, column_index, spec, write_col) |
| 61 | } |
| 62 | "cume_dist" => { |
| 63 | apply_v_cume_dist(rows, partition_indices, column_index, spec, write_col) |
| 64 | } |
| 65 | "lag" => apply_v_lag(rows, partition_indices, column_index, spec, write_col)?, |
| 66 | "lead" => apply_v_lead(rows, partition_indices, column_index, spec, write_col)?, |
| 67 | "nth_value" => { |
| 68 | apply_v_nth_value(rows, partition_indices, column_index, spec, write_col)? |
| 69 | } |
| 70 | "sum" | "count" | "avg" | "min" | "max" | "first_value" | "last_value" => { |
| 71 | apply_v_aggregate(rows, partition_indices, column_index, spec, write_col) |
| 72 | } |
| 73 | other => { |
| 74 | return Err(WindowError::ArgEval { |
| 75 | detail: format!( |
| 76 | "unknown window function '{other}'; valid names: row_number, rank, \ |
| 77 | dense_rank, ntile, percent_rank, cume_dist, lag, lead, nth_value, \ |
| 78 | sum, count, avg, min, max, first_value, last_value" |
| 79 | ), |
| 80 | }); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | new_cols.push(spec.alias.clone()); |
| 86 | } |
| 87 | |
| 88 | Ok(new_cols) |
| 89 | } |
| 90 | |
| 91 | // ── Partition building ──────────────────────────────────────────────────────── |
| 92 |