1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Observation implementation for collecting metrics.
//!
//! Mirroring `pyspark.sql.observation.Observation`.
use std::collections::HashMap;
/// An Observation for collecting metrics from a DataFrame.
///
/// Mirrors `pyspark.sql.observation.Observation`.
pub struct Observation {
name: String,
metrics: HashMap<String, String>,
}
impl Observation {
/// Create a new Observation with a name.
pub fn new(name: &str) -> Self {
Observation {
name: name.to_string(),
metrics: HashMap::new(),
}
}
/// Get the name of this Observation.
pub fn name(&self) -> &str {
&self.name
}
/// Get metrics from this Observation.
pub fn get(&self) -> HashMap<String, String> {
self.metrics.clone()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_observation_creation() {
let obs = Observation::new("test_obs");
assert_eq!(obs.name(), "test_obs");
assert!(obs.get().is_empty());
}
}