@@ -2,6 +2,43 @@ use std::collections::HashMap;
22
33use aw_models:: Event ;
44
5+ /// Merge events with the same values at the specified keys
6+ ///
7+ /// Doesn't care about if events are neighbouring or not, this transform merges
8+ /// all events with the same key.
9+ /// The timestamp will be the timestamp of the first event with a specific key value
10+ ///
11+ /// # Example 1
12+ /// A simple example only using one key
13+ ///
14+ /// ```ignore
15+ /// keys: ["a"]
16+ /// input:
17+ /// { duration: 1.0, data: { "a": 1 } }
18+ /// { duration: 1.0, data: { "a": 1 } }
19+ /// { duration: 1.0, data: { "a": 2 } }
20+ /// { duration: 1.0, data: { "b": 1 } }
21+ /// { duration: 1.0, data: { "a": 1 } }
22+ /// output:
23+ /// { duration: 3.0, data: { "a": 1 } }
24+ /// { duration: 1.0, data: { "a": 2 } }
25+ /// { duration: 1.0, data: { "b": 1 } }
26+ /// ```
27+ ///
28+ /// # Example 2
29+ /// A more complex example only using two keys
30+ /// ```ignore
31+ /// keys: ["a", "b"]
32+ /// input:
33+ /// { duration: 1.0, data: { "a": 1, "b": 1 } }
34+ /// { duration: 1.0, data: { "a": 2, "b": 2 } }
35+ /// { duration: 1.0, data: { "a": 1, "b": 1 } }
36+ /// { duration: 1.0, data: { "a": 1, "b": 2 } }
37+ /// output:
38+ /// { duration: 2.0, data: { "a": 1, "b": 1 } }
39+ /// { duration: 1.0, data: { "a": 2, "b": 2 } }
40+ /// { duration: 1.0, data: { "a": 1, "b": 2 } }
41+ /// ```
542#[ allow( clippy:: map_entry) ]
643pub fn merge_events_by_keys ( events : Vec < Event > , keys : Vec < String > ) -> Vec < Event > {
744 if keys. is_empty ( ) {
0 commit comments