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

Function sort_aggregated_rows

nodedb/src/data/executor/handlers/aggregate.rs:119–134  ·  view source on GitHub ↗

Sort aggregated rows by `sort_keys = [(column, ascending), ...]`. Each row is a `serde_json::Value::Object`; for every key, the extracted value is converted to a comparable form (numbers compared numerically, strings lexically, nulls last). Keys missing from a row sort as null. The sort is stable to preserve relative order of equal-key rows.

(rows: &mut [serde_json::Value], sort_keys: &[(String, bool)])

Source from the content-addressed store, hash-verified

117/// row sort as null. The sort is stable to preserve relative order of
118/// equal-key rows.
119fn sort_aggregated_rows(rows: &mut [serde_json::Value], sort_keys: &[(String, bool)]) {
120 if sort_keys.is_empty() {
121 return;
122 }
123 rows.sort_by(|a, b| {
124 for (column, ascending) in sort_keys {
125 let av = a.get(column);
126 let bv = b.get(column);
127 let ord = compare_json_values(av, bv);
128 if ord != std::cmp::Ordering::Equal {
129 return if *ascending { ord } else { ord.reverse() };
130 }
131 }
132 std::cmp::Ordering::Equal
133 });
134}
135
136/// Compare two `Option<&serde_json::Value>` for sort. Nulls / absent
137/// keys sort last; numbers compare numerically; everything else falls

Callers 1

execute_aggregateMethod · 0.85

Calls 3

compare_json_valuesFunction · 0.85
is_emptyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected