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

Function apply_v_per_row_aggregate

nodedb-query/src/window/value_agg.rs:111–170  ·  view source on GitHub ↗
(
    rows: &mut [Vec<Value>],
    indices: &[usize],
    column_index: &HashMap<String, usize>,
    spec: &WindowFuncSpec,
    write_col: usize,
)

Source from the content-addressed store, hash-verified

109}
110
111fn apply_v_per_row_aggregate(
112 rows: &mut [Vec<Value>],
113 indices: &[usize],
114 column_index: &HashMap<String, usize>,
115 spec: &WindowFuncSpec,
116 write_col: usize,
117) {
118 let len = indices.len();
119 if len == 0 {
120 return;
121 }
122
123 let order_expr = spec.order_by.first().map(|(expr, _)| expr);
124 let order_values: Vec<Value> = indices
125 .iter()
126 .map(|&i| {
127 order_expr
128 .and_then(|expr| {
129 rows.get(i)
130 .map(|row| eval_arg_for_row(expr, row, column_index))
131 })
132 .unwrap_or(Value::Null)
133 })
134 .collect();
135
136 let peer_groups: Vec<usize> = if spec.frame.mode == "groups" {
137 build_v_peer_groups(&order_values)
138 } else {
139 Vec::new()
140 };
141
142 let all_vals: Vec<Option<f64>> = indices
143 .iter()
144 .map(|&i| {
145 rows.get(i)
146 .map(|row| eval_arg(spec, row, column_index).as_f64())
147 .unwrap_or(None)
148 })
149 .collect();
150
151 let results: Vec<Value> = (0..len)
152 .map(|pos| {
153 let (start_idx, end_idx) =
154 evaluate_v_frame_bounds(&spec.frame, pos, len, &order_values, &peer_groups);
155 aggregate_v_slice(
156 &all_vals,
157 indices,
158 rows,
159 column_index,
160 spec,
161 start_idx,
162 end_idx,
163 )
164 })
165 .collect();
166
167 for (pos, result) in results.into_iter().enumerate() {
168 set_cell(rows, indices[pos], write_col, result);

Callers 1

apply_v_aggregateFunction · 0.85

Calls 12

eval_arg_for_rowFunction · 0.85
build_v_peer_groupsFunction · 0.85
eval_argFunction · 0.85
evaluate_v_frame_boundsFunction · 0.85
aggregate_v_sliceFunction · 0.85
set_cellFunction · 0.85
firstMethod · 0.80
collectMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
getMethod · 0.45
as_f64Method · 0.45

Tested by

no test coverage detected