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

Function build_partitions

nodedb-query/src/window/helpers.rs:10–35  ·  view source on GitHub ↗

Group row indices by partition key, preserving first-seen partition order.

(
    rows: &[(String, serde_json::Value)],
    partition_by: &[SqlExpr],
)

Source from the content-addressed store, hash-verified

8
9/// Group row indices by partition key, preserving first-seen partition order.
10pub(super) fn build_partitions(
11 rows: &[(String, serde_json::Value)],
12 partition_by: &[SqlExpr],
13) -> Vec<Vec<usize>> {
14 if partition_by.is_empty() {
15 return vec![(0..rows.len()).collect()];
16 }
17
18 let mut groups: HashMap<String, Vec<usize>> = HashMap::new();
19 let mut order = Vec::new();
20
21 for (i, (_id, doc)) in rows.iter().enumerate() {
22 let key: String = partition_by
23 .iter()
24 .map(|expr| eval_expr_on_json(expr, doc).to_string())
25 .collect::<Vec<_>>()
26 .join("\x00");
27 let entry = groups.entry(key.clone()).or_default();
28 if entry.is_empty() {
29 order.push(key);
30 }
31 entry.push(i);
32 }
33
34 order.iter().filter_map(|k| groups.remove(k)).collect()
35}
36
37pub(super) fn set_window_col(row: &mut serde_json::Value, alias: &str, val: serde_json::Value) {
38 if let serde_json::Value::Object(map) = row {

Callers 1

Calls 10

eval_expr_on_jsonFunction · 0.85
joinMethod · 0.80
to_stringMethod · 0.80
entryMethod · 0.80
collectMethod · 0.80
is_emptyMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected