Skip to main content

sql_splitter/redactor/strategy/
null.rs

1//! Null strategy - replace values with NULL.
2
3use super::{RedactValue, Strategy, StrategyKind};
4
5/// Strategy that replaces all values with NULL
6#[derive(Debug, Clone, Default)]
7pub struct NullStrategy;
8
9impl NullStrategy {
10    pub fn new() -> Self {
11        Self
12    }
13}
14
15impl Strategy for NullStrategy {
16    fn apply(&self, _value: &RedactValue, _rng: &mut dyn rand::RngCore) -> RedactValue {
17        // Always return NULL regardless of input
18        RedactValue::Null
19    }
20
21    fn kind(&self) -> StrategyKind {
22        StrategyKind::Null
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29    use rand::SeedableRng;
30
31    #[test]
32    fn test_null_strategy() {
33        let strategy = NullStrategy::new();
34        let mut rng = rand::rngs::StdRng::seed_from_u64(42);
35
36        // String becomes NULL
37        let result = strategy.apply(&RedactValue::String("test".to_string()), &mut rng);
38        assert!(matches!(result, RedactValue::Null));
39
40        // Integer becomes NULL
41        let result = strategy.apply(&RedactValue::Integer(123), &mut rng);
42        assert!(matches!(result, RedactValue::Null));
43
44        // NULL stays NULL
45        let result = strategy.apply(&RedactValue::Null, &mut rng);
46        assert!(matches!(result, RedactValue::Null));
47    }
48}