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

Function partition_by_field

nodedb/src/control/trigger/batch/partition.rs:76–90  ·  view source on GitHub ↗

Partition rows by a field value from NEW fields. Convenience wrapper: extracts `field_name` from each row's NEW fields and uses the string representation as the partition key.

(
    rows: &[TriggerBatchRow],
    field_name: &str,
    max_partitions: usize,
)

Source from the content-addressed store, hash-verified

74/// Convenience wrapper: extracts `field_name` from each row's NEW fields
75/// and uses the string representation as the partition key.
76pub fn partition_by_field(
77 rows: &[TriggerBatchRow],
78 field_name: &str,
79 max_partitions: usize,
80) -> PartitionResult {
81 partition_batch(rows, max_partitions, |row| {
82 row.new_fields()
83 .and_then(|m| m.get(field_name))
84 .map(|v| match v {
85 nodedb_types::Value::String(s) => s.clone(),
86 other => other.to_sql_literal(),
87 })
88 .unwrap_or_else(|| "__null__".to_string())
89 })
90}
91
92#[cfg(test)]
93mod tests {

Callers 4

partition_by_keyFunction · 0.85
circuit_breaker_triggersFunction · 0.85
single_partitionFunction · 0.85

Calls 6

partition_batchFunction · 0.85
new_fieldsMethod · 0.80
to_sql_literalMethod · 0.80
to_stringMethod · 0.80
getMethod · 0.45
cloneMethod · 0.45

Tested by 4

partition_by_keyFunction · 0.68
circuit_breaker_triggersFunction · 0.68
single_partitionFunction · 0.68