make InternalAggregation.reduce(ReduceContext) use template pattern
sub-classes of InternalAggregation now implement doReduce(ReduceContext) that is called from InternalAggregation.reduce(ReduceContext) which is now final
This commit is contained in:
parent
de41981373
commit
e2949d7df1
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.search.aggregations;
|
package org.elasticsearch.search.aggregations;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -146,7 +145,11 @@ public abstract class InternalAggregation implements Aggregation, ToXContent, St
|
||||||
* try reusing an existing get instance (typically the first in the given list) to save on redundant object
|
* try reusing an existing get instance (typically the first in the given list) to save on redundant object
|
||||||
* construction.
|
* construction.
|
||||||
*/
|
*/
|
||||||
public abstract InternalAggregation reduce(ReduceContext reduceContext);
|
public final InternalAggregation reduce(ReduceContext reduceContext) {
|
||||||
|
return doReduce(reduceContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract InternalAggregation doReduce(ReduceContext reduceContext);
|
||||||
|
|
||||||
public Object getProperty(String path) {
|
public Object getProperty(String path) {
|
||||||
AggregationPath aggPath = AggregationPath.parse(path);
|
AggregationPath aggPath = AggregationPath.parse(path);
|
||||||
|
|
|
@ -165,7 +165,7 @@ public class InternalAggregations implements Aggregations, ToXContent, Streamabl
|
||||||
for (Map.Entry<String, List<InternalAggregation>> entry : aggByName.entrySet()) {
|
for (Map.Entry<String, List<InternalAggregation>> entry : aggByName.entrySet()) {
|
||||||
List<InternalAggregation> aggregations = entry.getValue();
|
List<InternalAggregation> aggregations = entry.getValue();
|
||||||
InternalAggregation first = aggregations.get(0); // the list can't be empty as it's created on demand
|
InternalAggregation first = aggregations.get(0); // the list can't be empty as it's created on demand
|
||||||
reducedAggregations.add(first.reduce(new InternalAggregation.ReduceContext(aggregations, context.bigArrays(), context.scriptService())));
|
reducedAggregations.add(first.doReduce(new InternalAggregation.ReduceContext(aggregations, context.bigArrays(), context.scriptService())));
|
||||||
}
|
}
|
||||||
return new InternalAggregations(reducedAggregations);
|
return new InternalAggregations(reducedAggregations);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public abstract class InternalSingleBucketAggregation extends InternalAggregatio
|
||||||
protected abstract InternalSingleBucketAggregation newAggregation(String name, long docCount, InternalAggregations subAggregations);
|
protected abstract InternalSingleBucketAggregation newAggregation(String name, long docCount, InternalAggregations subAggregations);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
long docCount = 0L;
|
long docCount = 0L;
|
||||||
List<InternalAggregations> subAggregationsList = new ArrayList<>(aggregations.size());
|
List<InternalAggregations> subAggregationsList = new ArrayList<>(aggregations.size());
|
||||||
|
|
|
@ -191,7 +191,7 @@ public class InternalFilters extends InternalMultiBucketAggregation implements F
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
List<List<Bucket>> bucketsList = null;
|
List<List<Bucket>> bucketsList = null;
|
||||||
for (InternalAggregation aggregation : aggregations) {
|
for (InternalAggregation aggregation : aggregations) {
|
||||||
|
|
|
@ -188,7 +188,7 @@ public class InternalGeoHashGrid extends InternalMultiBucketAggregation implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalGeoHashGrid reduce(ReduceContext reduceContext) {
|
public InternalGeoHashGrid doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
|
|
||||||
LongObjectPagedHashMap<List<Bucket>> buckets = null;
|
LongObjectPagedHashMap<List<Bucket>> buckets = null;
|
||||||
|
|
|
@ -412,7 +412,7 @@ public class InternalHistogram<B extends InternalHistogram.Bucket> extends Inter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<B> reducedBuckets = reduceBuckets(reduceContext);
|
List<B> reducedBuckets = reduceBuckets(reduceContext);
|
||||||
|
|
||||||
// adding empty buckets if needed
|
// adding empty buckets if needed
|
||||||
|
|
|
@ -258,7 +258,7 @@ public class InternalRange<B extends InternalRange.Bucket> extends InternalMulti
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Bucket>[] rangeList = new List[ranges.size()];
|
List<Bucket>[] rangeList = new List[ranges.size()];
|
||||||
|
|
|
@ -156,7 +156,7 @@ public abstract class InternalSignificantTerms extends InternalMultiBucketAggreg
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
|
|
||||||
long globalSubsetSize = 0;
|
long globalSubsetSize = 0;
|
||||||
|
|
|
@ -68,10 +68,10 @@ public class UnmappedSignificantTerms extends InternalSignificantTerms {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
||||||
if (!(aggregation instanceof UnmappedSignificantTerms)) {
|
if (!(aggregation instanceof UnmappedSignificantTerms)) {
|
||||||
return aggregation.reduce(reduceContext);
|
return aggregation.doReduce(reduceContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -160,7 +160,7 @@ public abstract class InternalTerms extends InternalMultiBucketAggregation imple
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
|
|
||||||
Multimap<Object, InternalTerms.Bucket> buckets = ArrayListMultimap.create();
|
Multimap<Object, InternalTerms.Bucket> buckets = ArrayListMultimap.create();
|
||||||
|
|
|
@ -81,10 +81,10 @@ public class UnmappedTerms extends InternalTerms {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
for (InternalAggregation agg : reduceContext.aggregations()) {
|
for (InternalAggregation agg : reduceContext.aggregations()) {
|
||||||
if (!(agg instanceof UnmappedTerms)) {
|
if (!(agg instanceof UnmappedTerms)) {
|
||||||
return agg.reduce(reduceContext);
|
return agg.doReduce(reduceContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class InternalAvg extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAvg reduce(ReduceContext reduceContext) {
|
public InternalAvg doReduce(ReduceContext reduceContext) {
|
||||||
long count = 0;
|
long count = 0;
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
||||||
|
|
|
@ -99,7 +99,7 @@ public final class InternalCardinality extends InternalNumericMetricsAggregation
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
InternalCardinality reduced = null;
|
InternalCardinality reduced = null;
|
||||||
for (InternalAggregation aggregation : aggregations) {
|
for (InternalAggregation aggregation : aggregations) {
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class InternalGeoBounds extends InternalMetricsAggregation implements Geo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
double top = Double.NEGATIVE_INFINITY;
|
double top = Double.NEGATIVE_INFINITY;
|
||||||
double bottom = Double.POSITIVE_INFINITY;
|
double bottom = Double.POSITIVE_INFINITY;
|
||||||
double posLeft = Double.POSITIVE_INFINITY;
|
double posLeft = Double.POSITIVE_INFINITY;
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class InternalMax extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalMax reduce(ReduceContext reduceContext) {
|
public InternalMax doReduce(ReduceContext reduceContext) {
|
||||||
double max = Double.NEGATIVE_INFINITY;
|
double max = Double.NEGATIVE_INFINITY;
|
||||||
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
||||||
max = Math.max(max, ((InternalMax) aggregation).max);
|
max = Math.max(max, ((InternalMax) aggregation).max);
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class InternalMin extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalMin reduce(ReduceContext reduceContext) {
|
public InternalMin doReduce(ReduceContext reduceContext) {
|
||||||
double min = Double.POSITIVE_INFINITY;
|
double min = Double.POSITIVE_INFINITY;
|
||||||
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
||||||
min = Math.min(min, ((InternalMin) aggregation).min);
|
min = Math.min(min, ((InternalMin) aggregation).min);
|
||||||
|
|
|
@ -60,7 +60,7 @@ abstract class AbstractInternalPercentiles extends InternalNumericMetricsAggrega
|
||||||
public abstract double value(double key);
|
public abstract double value(double key);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractInternalPercentiles reduce(ReduceContext reduceContext) {
|
public AbstractInternalPercentiles doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
TDigestState merged = null;
|
TDigestState merged = null;
|
||||||
for (InternalAggregation aggregation : aggregations) {
|
for (InternalAggregation aggregation : aggregations) {
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class InternalScriptedMetric extends InternalMetricsAggregation implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<Object> aggregationObjects = new ArrayList<>();
|
List<Object> aggregationObjects = new ArrayList<>();
|
||||||
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
||||||
InternalScriptedMetric mapReduceAggregation = (InternalScriptedMetric) aggregation;
|
InternalScriptedMetric mapReduceAggregation = (InternalScriptedMetric) aggregation;
|
||||||
|
|
|
@ -148,7 +148,7 @@ public class InternalStats extends InternalNumericMetricsAggregation.MultiValue
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalStats reduce(ReduceContext reduceContext) {
|
public InternalStats doReduce(ReduceContext reduceContext) {
|
||||||
long count = 0;
|
long count = 0;
|
||||||
double min = Double.POSITIVE_INFINITY;
|
double min = Double.POSITIVE_INFINITY;
|
||||||
double max = Double.NEGATIVE_INFINITY;
|
double max = Double.NEGATIVE_INFINITY;
|
||||||
|
|
|
@ -143,13 +143,13 @@ public class InternalExtendedStats extends InternalStats implements ExtendedStat
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalExtendedStats reduce(ReduceContext reduceContext) {
|
public InternalExtendedStats doReduce(ReduceContext reduceContext) {
|
||||||
double sumOfSqrs = 0;
|
double sumOfSqrs = 0;
|
||||||
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
||||||
InternalExtendedStats stats = (InternalExtendedStats) aggregation;
|
InternalExtendedStats stats = (InternalExtendedStats) aggregation;
|
||||||
sumOfSqrs += stats.getSumOfSquares();
|
sumOfSqrs += stats.getSumOfSquares();
|
||||||
}
|
}
|
||||||
final InternalStats stats = super.reduce(reduceContext);
|
final InternalStats stats = super.doReduce(reduceContext);
|
||||||
return new InternalExtendedStats(name, stats.getCount(), stats.getSum(), stats.getMin(), stats.getMax(), sumOfSqrs, sigma, valueFormatter, getMetaData());
|
return new InternalExtendedStats(name, stats.getCount(), stats.getSum(), stats.getMin(), stats.getMax(), sumOfSqrs, sigma, valueFormatter, getMetaData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class InternalSum extends InternalNumericMetricsAggregation.SingleValue i
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalSum reduce(ReduceContext reduceContext) {
|
public InternalSum doReduce(ReduceContext reduceContext) {
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
||||||
sum += ((InternalSum) aggregation).sum;
|
sum += ((InternalSum) aggregation).sum;
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class InternalTopHits extends InternalMetricsAggregation implements TopHi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
List<InternalAggregation> aggregations = reduceContext.aggregations();
|
||||||
TopDocs[] shardDocs = new TopDocs[aggregations.size()];
|
TopDocs[] shardDocs = new TopDocs[aggregations.size()];
|
||||||
InternalSearchHits[] shardHits = new InternalSearchHits[aggregations.size()];
|
InternalSearchHits[] shardHits = new InternalSearchHits[aggregations.size()];
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class InternalValueCount extends InternalNumericMetricsAggregation.Single
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InternalAggregation reduce(ReduceContext reduceContext) {
|
public InternalAggregation doReduce(ReduceContext reduceContext) {
|
||||||
long valueCount = 0;
|
long valueCount = 0;
|
||||||
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
for (InternalAggregation aggregation : reduceContext.aggregations()) {
|
||||||
valueCount += ((InternalValueCount) aggregation).value;
|
valueCount += ((InternalValueCount) aggregation).value;
|
||||||
|
|
Loading…
Reference in New Issue