From 13944b1bf9ff00a20b965d6bfadbcf2e16fc6960 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Thu, 7 May 2020 14:29:48 -0700 Subject: [PATCH] Fix max-int limit for number of points reduced in geo_centroid (#56370) A bug in InternalGeoCentroid#reduce existed that summed up the aggregation's long-valued counts into a local integer variable. Since it is definitely possible to reduce more than Integer.MAX points, this change simply updates that variable to be a long-valued number. Closes #55992. --- .../aggregations/metrics/InternalGeoCentroid.java | 2 +- .../metrics/InternalGeoCentroidTests.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalGeoCentroid.java b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalGeoCentroid.java index 1bd51f15487..a2ad659cfe1 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalGeoCentroid.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/metrics/InternalGeoCentroid.java @@ -115,7 +115,7 @@ public class InternalGeoCentroid extends InternalAggregation implements GeoCentr public InternalGeoCentroid reduce(List aggregations, ReduceContext reduceContext) { double lonSum = Double.NaN; double latSum = Double.NaN; - int totalCount = 0; + long totalCount = 0; for (InternalAggregation aggregation : aggregations) { InternalGeoCentroid centroidAgg = (InternalGeoCentroid) aggregation; if (centroidAgg.count > 0) { diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalGeoCentroidTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalGeoCentroidTests.java index 277f81e079d..9eff420f1df 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalGeoCentroidTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalGeoCentroidTests.java @@ -29,6 +29,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.hamcrest.Matchers.equalTo; + public class InternalGeoCentroidTests extends InternalAggregationTestCase { @Override @@ -52,7 +54,7 @@ public class InternalGeoCentroidTests extends InternalAggregationTestCase inputs) { double lonSum = 0; double latSum = 0; - int totalCount = 0; + long totalCount = 0; for (InternalGeoCentroid input : inputs) { if (input.count() > 0) { lonSum += (input.count() * input.centroid().getLon()); @@ -67,6 +69,14 @@ public class InternalGeoCentroidTests extends InternalAggregationTestCase