fixed the reduce of InternalGeoHashGrid when executing on a single shard
This commit is contained in:
parent
f4411e697e
commit
2f32908193
|
@ -93,8 +93,6 @@ public class GeoHashGridAggregator extends BucketsAggregator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalGeoHashGrid buildAggregation(long owningBucketOrdinal) {
|
public InternalGeoHashGrid buildAggregation(long owningBucketOrdinal) {
|
||||||
assert owningBucketOrdinal == 0;
|
assert owningBucketOrdinal == 0;
|
||||||
|
|
|
@ -169,7 +169,7 @@ public class InternalGeoHashGrid extends InternalAggregation implements GeoHashG
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
if (aggregations.size() == 1) {
|
if (aggregations.size() == 1) {
|
||||||
InternalGeoHashGrid grid = (InternalGeoHashGrid) aggregations.get(0);
|
InternalGeoHashGrid grid = (InternalGeoHashGrid) aggregations.get(0);
|
||||||
grid.trimExcessEntries(reduceContext.cacheRecycler());
|
grid.reduceAndTrimBuckets(reduceContext.cacheRecycler());
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
InternalGeoHashGrid reduced = null;
|
InternalGeoHashGrid reduced = null;
|
||||||
|
@ -230,16 +230,24 @@ public class InternalGeoHashGrid extends InternalAggregation implements GeoHashG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void trimExcessEntries(CacheRecycler cacheRecycler) {
|
protected void reduceAndTrimBuckets(CacheRecycler cacheRecycler) {
|
||||||
int i = 0;
|
|
||||||
for (Iterator<Bucket> iter = buckets.iterator(); iter.hasNext();) {
|
if (requiredSize > buckets.size()) { // nothing to trim
|
||||||
Bucket bucket = iter.next();
|
for (Bucket bucket : buckets) {
|
||||||
if (i++ >= requiredSize) {
|
|
||||||
iter.remove();
|
|
||||||
} else {
|
|
||||||
bucket.aggregations.reduce(cacheRecycler);
|
bucket.aggregations.reduce(cacheRecycler);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Bucket> trimmedBuckets = new ArrayList<Bucket>(requiredSize);
|
||||||
|
for (Bucket bucket : buckets) {
|
||||||
|
if (trimmedBuckets.size() >= requiredSize) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bucket.aggregations.reduce(cacheRecycler);
|
||||||
|
trimmedBuckets.add(bucket);
|
||||||
|
}
|
||||||
|
buckets = trimmedBuckets;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue