Merge dbsp/live-source into dbsp/pushdown

This commit is contained in:
Claude (dbsp-sources)
2026-10-10 19:52:55 -07:00
committed by Edward Langley
3 changed files with 33 additions and 9 deletions
+25 -5
View File
@@ -70,7 +70,13 @@ impl Numbers {
greatest: Option<f64>,
) -> Result<Self, BadParts> {
let bad = |why| Err(BadParts(why));
if count == 0 && sum != ExactSum::new() {
return bad("a sum with no numbers");
}
match (least, greatest) {
(None, None) if count > 0 && !sum.value().is_nan() => {
return bad("no extremes but a sum that is not NaN");
}
(None, None) => {}
(Some(_), Some(_)) if count == 0 => return bad("extremes with no numbers"),
(Some(l), Some(g)) if l.is_nan() || g.is_nan() => return bad("a NaN extreme"),
@@ -535,13 +541,15 @@ mod tests {
#[test]
fn the_exact_sum_of_a_pool_of_cancelling_values_is_not_the_sum_of_rounded_parts() {
let rounded = [1e16, 1.0].iter().sum::<f64>() + [-1e16].iter().sum::<f64>();
let mut pooled = Numbers::of([1e16, 1.0]);
pooled.merge(&Numbers::of([-1e16]));
assert_eq!(
rounded, 0.0,
"the fixture is inexact: summing rounded parts loses the 1"
"the fixture is inexact: rounded parts lose the 1"
);
assert_eq!(pooled.total(), 1.0);
for (first, second) in [([1e16, 1.0], [-1e16, 0.0]), ([-1e16, 0.0], [1e16, 1.0])] {
let mut pooled = Numbers::of(first);
pooled.merge(&Numbers::of(second));
assert_eq!(pooled.total(), 1.0, "{first:?} then {second:?}");
}
}
fn pair(c: &str, i: &str) -> (String, String) {
@@ -854,7 +862,19 @@ mod tests {
refused(Numbers::from_parts(2, sum(), Some(1.0), None)),
"one extreme without the other"
);
let ok = Numbers::from_parts(2, sum(), None, None).unwrap();
let mut one = ExactSum::new();
one.add(1.0, 1);
assert_eq!(
refused(Numbers::from_parts(0, one.clone(), None, None)),
"a sum with no numbers"
);
assert_eq!(
refused(Numbers::from_parts(2, one, None, None)),
"no extremes but a sum that is not NaN"
);
let mut nan = ExactSum::new();
nan.add(f64::NAN, 1);
let ok = Numbers::from_parts(2, nan, None, None).unwrap();
assert!(
ok.reduce(&AggFunc::Min).unwrap().is_nan(),
"all NaN: no extremes, a count"