Skip to content

Commit 6e6ea49

Browse files
authored
Use a long to properly track added samples (#96912)
* Use a long to properly track added samples. This helps avoid warnings around implicit conversions from long to integer values in SortingDigest. * Update docs/changelog/96912.yaml * Another fix for invalid type conversion. * Update docs/changelog/96912.yaml
1 parent 8ebe228 commit 6e6ea49

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

docs/changelog/96912.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 96912
2+
summary: Use a long to properly track added samples
3+
area: Aggregations
4+
type: bug
5+
issues:
6+
- 96911

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ public void add(double x, int w) {
5252

5353
@Override
5454
public void add(List<? extends TDigest> others) {
55-
int valuesToAddCount = 0;
55+
long valuesToAddCount = 0;
5656
for (TDigest other : others) {
5757
valuesToAddCount += other.size();
5858
}
59-
values.ensureCapacity(valuesToAddCount + values.size());
59+
reserve(valuesToAddCount);
6060

6161
for (TDigest other : others) {
6262
for (Centroid centroid : other.centroids()) {

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,18 @@ public void testSize() {
6060
double k0 = k.k(0, compression, n);
6161
int m = 0;
6262
for (int i = 0; i < n;) {
63-
double cnt = 1;
64-
while (i + cnt < n && k.k((i + cnt + 1) / (n - 1), compression, n) - k0 < 1) {
63+
int cnt = 1;
64+
while (i + cnt < n && k.k((i + cnt + 1.0) / (n - 1.0), compression, n) - k0 < 1) {
6565
cnt++;
6666
}
67-
double size = n * max(k.max(i / (n - 1), compression, n), k.max((i + cnt) / (n - 1), compression, n));
67+
double size = n * max(k.max(i / (n - 1), compression, n), k.max((i + cnt) / (n - 1.0), compression, n));
6868

6969
// check that we didn't cross the midline (which makes the size limit very conservative)
7070
double left = i - (n - 1) / 2;
7171
double right = i + cnt - (n - 1) / 2;
7272
boolean sameSide = left * right > 0;
7373
if (k.toString().endsWith("NO_NORM") == false && sameSide) {
74-
assertTrue(
75-
String.format(Locale.ROOT, "%s %.0f %.0f %.3f vs %.3f @ %.3f", k, compression, n, cnt, size, i / (n - 1)),
76-
cnt == 1 || cnt <= max(1.1 * size, size + 1)
77-
);
74+
assertTrue(cnt == 1 || cnt <= max(1.1 * size, size + 1));
7875
}
7976
i += cnt;
8077
k0 = k.k(i / (n - 1), compression, n);

0 commit comments

Comments
 (0)