Skip to content
Draft
Show file tree
Hide file tree
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
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ version = "0.1.0"
# The backend depends on two Planner crates, at one immutable revision:
# `asap-planner` to plan and `asap-executor` to execute. Planner IR types
# are reached through `asap_executor::planner`.
asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "b9c7fdfa09f8854d4ae201183637038ee0f6bd36" }
asap-executor = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "b9c7fdfa09f8854d4ae201183637038ee0f6bd36" }
asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "71137c2141e79a5911c53482a2baa75dbff80847" }
asap-executor = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "71137c2141e79a5911c53482a2baa75dbff80847" }
# The sketch library the Planner's executor pins, for the byte encodings of
# the sketch states the data plane persists; keep it at the Planner's rev
# (draft: ASAPPlanner#1553 head, for SIL intents).
Expand Down
2 changes: 1 addition & 1 deletion data_plane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ form_urlencoded = "1"

[dev-dependencies]
# Parses SIL intents for the intent round loop's end-to-end test.
asap-frontend-sil = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "b9c7fdfa09f8854d4ae201183637038ee0f6bd36" }
asap-frontend-sil = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "71137c2141e79a5911c53482a2baa75dbff80847" }
# Paused time for the intent loop's latency and overrun tests.
tokio = { workspace = true, features = ["test-util"] }
control_plane.workspace = true
Expand Down
1 change: 1 addition & 0 deletions data_plane/src/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ fn compact_kind(family: &FieldDataType) -> Option<CompactKind> {
ExactKind::Min | ExactKind::Max => CompactKind::MinMax,
ExactKind::Counter => CompactKind::Counter,
ExactKind::IRate => CompactKind::LastTwoSamples,
ExactKind::SumOfSquaredDeviations => CompactKind::SumOfSquaredDeviations,
},
_ => return None,
})
Expand Down
46 changes: 46 additions & 0 deletions data_plane/src/state_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub enum CompactKind {
Counter,
/// Exact last two samples: two of (`present`, `timestamp`, `value`).
LastTwoSamples,
/// Exact sum of squared deviations (a standard deviation's or
/// variance's state): `count` (u64), `mean`, `sum_squared_deviations`
/// (f64); an empty one is all zero.
SumOfSquaredDeviations,
}

impl CompactKind {
Expand All @@ -53,6 +57,7 @@ impl CompactKind {
Self::MinMax => 4,
Self::Counter => 5,
Self::LastTwoSamples => 6,
Self::SumOfSquaredDeviations => 7,
}
}

Expand All @@ -64,6 +69,7 @@ impl CompactKind {
4 => Self::MinMax,
5 => Self::Counter,
6 => Self::LastTwoSamples,
7 => Self::SumOfSquaredDeviations,
_ => return None,
})
}
Expand All @@ -77,6 +83,7 @@ impl CompactKind {
Self::MinMax => 16,
Self::Counter => 56,
Self::LastTwoSamples => 48,
Self::SumOfSquaredDeviations => 24,
})
}
}
Expand Down Expand Up @@ -695,6 +702,13 @@ fn put_record(
}
}
}
(CompactKind::SumOfSquaredDeviations, [0, 0, 0]) => out.ints.push(0),
(CompactKind::SumOfSquaredDeviations, [count, mean, squared_deviations]) if *count > 0 => {
out.ints.push(1);
put_uvarint(&mut out.ints, *count);
out.floats[0].push(*mean);
out.floats[1].push(*squared_deviations);
}
_ => return false,
}
true
Expand Down Expand Up @@ -818,6 +832,13 @@ fn record(
}
&words[..6]
}
(CompactKind::SumOfSquaredDeviations, 0) => &words[..3],
(CompactKind::SumOfSquaredDeviations, 1) => {
words[0] = reader.uvarint()?;
words[1] = reader.float(0)?;
words[2] = reader.float(1)?;
&words[..3]
}
_ => return None,
};
view.extend_from_slice(record);
Expand Down Expand Up @@ -983,6 +1004,31 @@ mod tests {
words.iter().flat_map(|w| w.to_le_bytes()).collect()
}

/// A sum-of-squared-deviations column (count, mean, sum of squared
/// deviations) decodes to the bytes it was encoded from: an empty
/// record (all zero, one tag byte), records of a large mean and a
/// NaN, and one the executor never writes (count 0, mean non-zero,
/// kept whole).
#[test]
fn compact_sum_of_squared_deviations_columns_rebuild_the_records() {
let f = f64::to_bits;
let states = vec![
words(&[0, 0, 0]),
words(&[3, f(7.0 / 3.0), f(14.0 / 3.0)]),
words(&[10_000, f(1e9 + 0.25), f(3_367.5)]),
words(&[2, f(f64::NAN), f(f64::NAN)]),
words(&[0, f(1.0), 0]),
];
assert_eq!(
round_trip(CompactKind::SumOfSquaredDeviations, &states),
states
);
assert_eq!(
CompactKind::from_code(CompactKind::SumOfSquaredDeviations.code()),
Some(CompactKind::SumOfSquaredDeviations)
);
}

/// Every exact record kind decodes to the bytes it was encoded from,
/// including records the executor never writes (kept whole).
#[test]
Expand Down