Skip to main content

spark_connect/
observation.rs

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