Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions data_plane/src/precompute_engine/operators/univmon_accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ impl UnivMonAccumulator {
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
let inner = UnivMon::deserialize_from_bytes(bytes)
.map_err(|e| format!("invalid UnivMon state: {e}"))?;
if !inner.accepts_standard_updates() {
return Err(
"terminal-mode UnivMon state cannot enter the standard-update accumulator".into(),
);
}
Ok(Self { inner })
}

Expand Down Expand Up @@ -196,6 +201,17 @@ mod tests {
assert!((read(&restored, Statistic::FrequencyEntropy) - 1.0).abs() < 0.01);
}

/// Terminal-mode serialization is valid sketchlib state but not this accumulator's update domain.
#[test]
fn terminal_state_is_rejected_before_ingestion_or_merge() {
let mut state = UnivMon::init_univmon(4, 3, 16, 2);
state.fast_insert(&DataInput::U64(1), 1);
let bytes = state.serialize_to_bytes().unwrap();
assert!(UnivMonAccumulator::from_bytes(&bytes).is_err());
state.free();
assert!(UnivMonAccumulator::from_bytes(&state.serialize_to_bytes().unwrap()).is_ok());
}

/// Pane merge preserves overlapping keys and reset removes the previous window.
#[test]
fn merge_and_reset_preserve_frequency_semantics() {
Expand Down
Loading