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

Function custom_key_fn

nodedb/src/control/trigger/batch/partition.rs:181–206  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

179
180 #[test]
181 fn custom_key_fn() {
182 let rows = vec![
183 row_with_field("r1", "score", "10"),
184 row_with_field("r2", "score", "90"),
185 row_with_field("r3", "score", "50"),
186 ];
187
188 match partition_batch(&rows, 32, |row| {
189 let score: i64 = row
190 .new_fields()
191 .and_then(|m| m.get("score"))
192 .and_then(|v| v.as_str())
193 .and_then(|s| s.parse().ok())
194 .unwrap_or(0);
195 if score >= 50 {
196 "high".into()
197 } else {
198 "low".into()
199 }
200 }) {
201 PartitionResult::Partitions(parts) => {
202 assert_eq!(parts.len(), 2);
203 }
204 PartitionResult::CircuitBroken { .. } => panic!("unexpected"),
205 }
206 }
207}

Callers

nothing calls this directly

Calls 6

partition_batchFunction · 0.85
new_fieldsMethod · 0.80
getMethod · 0.45
as_strMethod · 0.45
okMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected