Skip to content

Commit eed3754

Browse files
authored
[8.15] Force using the last centroid during merging (#111644) (#112209)
* [8.15] Force using the last centroid during merging * update test
1 parent 5255222 commit eed3754

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

libs/tdigest/src/main/java/org/elasticsearch/tdigest/MergingDigest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,13 @@ private void merge(
302302
addThis = projectedW <= wLimit;
303303
}
304304
if (i == 1 || i == incomingCount - 1) {
305-
// force last centroid to never merge
305+
// force first and last centroid to never merge
306306
addThis = false;
307307
}
308+
if (lastUsedCell == mean.length - 1) {
309+
// use the last centroid, there's no more
310+
addThis = true;
311+
}
308312

309313
if (addThis) {
310314
// next point will fit

libs/tdigest/src/test/java/org/elasticsearch/tdigest/MergingDigestTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,14 @@ public void testFill() {
151151
i++;
152152
}
153153
}
154+
155+
public void testLargeInputSmallCompression() {
156+
MergingDigest td = new MergingDigest(10);
157+
for (int i = 0; i < 10_000_000; i++) {
158+
td.add(between(0, 3_600_000));
159+
}
160+
assertTrue(td.centroidCount() < 100);
161+
assertTrue(td.quantile(0.00001) < 100_000);
162+
assertTrue(td.quantile(0.99999) > 3_000_000);
163+
}
154164
}

libs/tdigest/src/test/java/org/elasticsearch/tdigest/TDigestTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void testQuantile() {
152152
hist2.compress();
153153
double x1 = hist1.quantile(0.5);
154154
double x2 = hist2.quantile(0.5);
155-
assertEquals(Dist.quantile(0.5, data), x1, 0.2);
155+
assertEquals(Dist.quantile(0.5, data), x1, 0.25);
156156
assertEquals(x1, x2, 0.01);
157157
}
158158

0 commit comments

Comments
 (0)