Skip to content

Commit 0cbb97f

Browse files
committed
Merge remote-tracking branch 'origin/issue-16990-percentile-cont' into issue-16990-percentile-cont
# Conflicts: # datafusion/functions-aggregate/src/approx_percentile_cont.rs # datafusion/functions-aggregate/src/approx_percentile_cont_with_weight.rs
2 parents f2b1de7 + 0cd3d8e commit 0cbb97f

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

datafusion/functions-aggregate/src/approx_percentile_cont.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,41 @@ mod tests {
565565
accumulator.merge_digests(&[t2]);
566566
assert_eq!(accumulator.digest.count(), 100_000);
567567
}
568+
569+
#[test]
570+
fn test_merge_digests_preserves_max_size() {
571+
// Create accumulator with specific max_size
572+
let original_max_size = 200;
573+
let mut accumulator = ApproxPercentileAccumulator::new_with_max_size(
574+
0.5,
575+
DataType::Float64,
576+
original_max_size,
577+
);
578+
579+
// Verify initial max_size
580+
assert_eq!(accumulator.digest.max_size(), original_max_size);
581+
582+
// Create new TDigests with different max_size
583+
let different_max_size = 50;
584+
let mut new_digests: Vec<TDigest> = Vec::new();
585+
586+
for _ in 1..=5 {
587+
let t = TDigest::new(different_max_size);
588+
let values: Vec<_> = (1..=1_000).map(f64::from).collect();
589+
let t = t.merge_unsorted_f64(values);
590+
new_digests.push(t);
591+
}
592+
593+
accumulator.merge_digests(&new_digests);
594+
assert_eq!(
595+
accumulator.digest.max_size(),
596+
original_max_size,
597+
"merge_digests should preserve the accumulator's original max_size"
598+
);
599+
assert_eq!(
600+
accumulator.digest.count(),
601+
5_000,
602+
"Data should have been merged"
603+
);
604+
}
568605
}

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ d 124
18321832
e 115
18331833

18341834
query TI
1835-
SELECT c1, approx_percentile_cont_with_weight(c2, 0.95) WITHIN GROUP (ORDER BY c3) AS c3_p95 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1
1835+
SELECT c1, approx_percentile_cont_with_weight(c2, 0.95, 200) WITHIN GROUP (ORDER BY c3) AS c3_p95 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1
18361836
----
18371837
a 74
18381838
b 68

0 commit comments

Comments
 (0)