fixed the reduce of InternalGeoHashGrid when executing on a single shard

This commit is contained in:
uboness 2014-01-23 21:09:01 +01:00
parent f4411e697e
commit 2f32908193
2 changed files with 16 additions and 10 deletions

View File

@ -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;

View File

@ -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