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,
)
| 74 | /// Convenience wrapper: extracts `field_name` from each row's NEW fields |
| 75 | /// and uses the string representation as the partition key. |
| 76 | pub 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)] |
| 93 | mod tests { |