MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / evaluate_window_functions_value

Function evaluate_window_functions_value

nodedb-query/src/window/value_eval.rs:36–89  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

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.
36pub 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

Callers 10

row_number_sequentialFunction · 0.85
rank_handles_tiesFunction · 0.85
dense_rank_handles_tiesFunction · 0.85
ntile_bucketsFunction · 0.85
lag_default_and_offsetFunction · 0.85
lead_boundaryFunction · 0.85
unknown_function_errorsFunction · 0.85

Calls 15

build_value_partitionsFunction · 0.85
apply_v_row_numberFunction · 0.85
apply_v_rankFunction · 0.85
apply_v_dense_rankFunction · 0.85
apply_v_ntileFunction · 0.85
apply_v_percent_rankFunction · 0.85
apply_v_cume_distFunction · 0.85
apply_v_lagFunction · 0.85
apply_v_leadFunction · 0.85
apply_v_nth_valueFunction · 0.85
apply_v_aggregateFunction · 0.85
firstMethod · 0.80

Tested by 10

row_number_sequentialFunction · 0.68
rank_handles_tiesFunction · 0.68
dense_rank_handles_tiesFunction · 0.68
ntile_bucketsFunction · 0.68
lag_default_and_offsetFunction · 0.68
lead_boundaryFunction · 0.68
unknown_function_errorsFunction · 0.68