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

Function build_value_partitions

nodedb-query/src/window/value_eval.rs:93–115  ·  view source on GitHub ↗
(
    rows: &[Vec<Value>],
    column_index: &HashMap<String, usize>,
    spec: &WindowFuncSpec,
)

Source from the content-addressed store, hash-verified

91// ── Partition building ────────────────────────────────────────────────────────
92
93fn build_value_partitions(
94 rows: &[Vec<Value>],
95 column_index: &HashMap<String, usize>,
96 spec: &WindowFuncSpec,
97) -> Result<Vec<Vec<usize>>, WindowError> {
98 if spec.partition_by.is_empty() {
99 return Ok(vec![(0..rows.len()).collect()]);
100 }
101
102 let mut groups: HashMap<String, Vec<usize>> = HashMap::new();
103 let mut order: Vec<String> = Vec::new();
104
105 for (i, row) in rows.iter().enumerate() {
106 let key = partition_key(row, column_index, &spec.partition_by);
107 let entry = groups.entry(key.clone()).or_default();
108 if entry.is_empty() {
109 order.push(key);
110 }
111 entry.push(i);
112 }
113
114 Ok(order.iter().filter_map(|k| groups.remove(k)).collect())
115}
116
117fn partition_key(
118 row: &[Value],

Callers 1

Calls 8

entryMethod · 0.80
collectMethod · 0.80
partition_keyFunction · 0.70
is_emptyMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected