From ed7b759a45e01bbc0526503abbcd8bca6f6b9cdf Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 15 Apr 2016 12:23:09 -0400 Subject: [PATCH] Cut max, min, stats, and extended stats aggregations over to registerAggregation and remove their PROTOTYPEs. Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 16 ++++--- .../metrics/max/MaxAggregatorBuilder.java | 42 ++++++++++------- .../aggregations/metrics/max/MaxParser.java | 11 ----- .../metrics/min/MinAggregatorBuilder.java | 43 +++++++++++------- .../aggregations/metrics/min/MinParser.java | 10 ----- .../metrics/stats/StatsAggregatorBuilder.java | 37 +++++++++------ .../metrics/stats/StatsParser.java | 11 ----- .../ExtendedStatsAggregatorBuilder.java | 45 ++++++++++++------- .../stats/extended/ExtendedStatsParser.java | 11 ----- .../metrics/sum/SumAggregatorBuilder.java | 42 ++++++++++------- .../aggregations/metrics/sum/SumParser.java | 11 ----- 11 files changed, 143 insertions(+), 136 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index f4b3aa6095c..09fe3c3b3eb 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -167,8 +167,10 @@ import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggr import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidParser; import org.elasticsearch.search.aggregations.metrics.geocentroid.InternalGeoCentroid; import org.elasticsearch.search.aggregations.metrics.max.InternalMax; +import org.elasticsearch.search.aggregations.metrics.max.MaxAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.max.MaxParser; import org.elasticsearch.search.aggregations.metrics.min.InternalMin; +import org.elasticsearch.search.aggregations.metrics.min.MinAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.min.MinParser; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksParser; @@ -181,10 +183,13 @@ import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.Interna import org.elasticsearch.search.aggregations.metrics.scripted.InternalScriptedMetric; import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.stats.InternalStats; +import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.stats.StatsParser; +import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsParser; import org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats; import org.elasticsearch.search.aggregations.metrics.sum.InternalSum; +import org.elasticsearch.search.aggregations.metrics.sum.SumAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.sum.SumParser; import org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits; import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregatorBuilder; @@ -457,11 +462,12 @@ public class SearchModule extends AbstractModule { SignificanceHeuristicParserMapper significanceHeuristicParserMapper = new SignificanceHeuristicParserMapper(heuristicParsers); registerAggregation(AvgAggregatorBuilder::new, new AvgParser(), AvgAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerAggregatorParser(new SumParser()); - registerAggregatorParser(new MinParser()); - registerAggregatorParser(new MaxParser()); - registerAggregatorParser(new StatsParser()); - registerAggregatorParser(new ExtendedStatsParser()); + registerAggregation(SumAggregatorBuilder::new, new SumParser(), SumAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerAggregation(MinAggregatorBuilder::new, new MinParser(), MinAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerAggregation(MaxAggregatorBuilder::new, new MaxParser(), MaxAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerAggregation(StatsAggregatorBuilder::new, new StatsParser(), StatsAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerAggregation(ExtendedStatsAggregatorBuilder::new, new ExtendedStatsParser(), + ExtendedStatsAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(ValueCountAggregatorBuilder::new, new ValueCountParser(), ValueCountAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(PercentilesAggregatorBuilder::new, new PercentilesParser(), PercentilesAggregatorBuilder.AGGREGATION_NAME_FIELD); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java index 2eb86535ca0..3b71dcb6bf5 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java @@ -19,47 +19,53 @@ package org.elasticsearch.search.aggregations.metrics.max; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.ToXContent.Params; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import java.io.IOException; public class MaxAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final MaxAggregatorBuilder PROTOTYPE = new MaxAggregatorBuilder(""); + public static final String NAME = InternalMax.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public MaxAggregatorBuilder(String name) { super(name, InternalMax.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); } + /** + * Read from a stream. + */ + public MaxAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalMax.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + @Override protected MaxAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { return new MaxAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); } - @Override - protected MaxAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new MaxAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { return builder; @@ -75,4 +81,8 @@ public class MaxAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly return true; } + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java index 50b622f9019..41c321acf33 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java @@ -37,11 +37,6 @@ public class MaxParser extends NumericValuesSourceParser { super(true, true, false); } - @Override - public String type() { - return InternalMax.TYPE.name(); - } - @Override protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser, ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException { @@ -53,10 +48,4 @@ public class MaxParser extends NumericValuesSourceParser { ValueType targetValueType, Map otherOptions) { return new MaxAggregatorBuilder(aggregationName); } - - @Override - public MaxAggregatorBuilder getFactoryPrototypes() { - return MaxAggregatorBuilder.PROTOTYPE; - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java index 186c38d26d3..25049bd71b0 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java @@ -19,47 +19,53 @@ package org.elasticsearch.search.aggregations.metrics.min; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.ToXContent.Params; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import java.io.IOException; public class MinAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final MinAggregatorBuilder PROTOTYPE = new MinAggregatorBuilder(""); + public static final String NAME = InternalMin.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public MinAggregatorBuilder(String name) { super(name, InternalMin.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); } + /** + * Read from a stream. + */ + public MinAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalMin.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + @Override protected MinAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { return new MinAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); } - @Override - protected MinAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new MinAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { return builder; @@ -74,4 +80,9 @@ public class MinAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly protected boolean innerEquals(Object obj) { return true; } + + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java index f7a3a04c6ae..9f9eafc5035 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java @@ -38,11 +38,6 @@ public class MinParser extends NumericValuesSourceParser { super(true, true, false); } - @Override - public String type() { - return InternalMin.TYPE.name(); - } - @Override protected boolean token(String aggregationName, String currentFieldName, Token token, XContentParser parser, ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException { @@ -54,9 +49,4 @@ public class MinParser extends NumericValuesSourceParser { ValueType targetValueType, Map otherOptions) { return new MinAggregatorBuilder(aggregationName); } - - @Override - public MinAggregatorBuilder getFactoryPrototypes() { - return MinAggregatorBuilder.PROTOTYPE; - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java index 646332f97ad..6775b9a9610 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java @@ -19,30 +19,42 @@ package org.elasticsearch.search.aggregations.metrics.stats; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.ToXContent.Params; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import java.io.IOException; public class StatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final StatsAggregatorBuilder PROTOTYPE = new StatsAggregatorBuilder(""); + public static final String NAME = InternalStats.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public StatsAggregatorBuilder(String name) { super(name, InternalStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); } + /** + * Read from a stream. + */ + public StatsAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + @Override protected StatsAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { @@ -50,14 +62,8 @@ public class StatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOn } @Override - protected StatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new StatsAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream + protected boolean usesNewStyleSerialization() { + return true; } @Override @@ -74,4 +80,9 @@ public class StatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOn protected boolean innerEquals(Object obj) { return true; } + + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java index 6bf558d197d..a57ba89b676 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.metrics.stats; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; @@ -38,11 +37,6 @@ public class StatsParser extends NumericValuesSourceParser { super(true, true, false); } - @Override - public String type() { - return InternalStats.TYPE.name(); - } - @Override protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser, ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException { @@ -54,9 +48,4 @@ public class StatsParser extends NumericValuesSourceParser { ValueType targetValueType, Map otherOptions) { return new StatsAggregatorBuilder(aggregationName); } - - @Override - public AggregatorBuilder getFactoryPrototypes() { - return StatsAggregatorBuilder.PROTOTYPE; - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java index 80fd04b6c18..c5b6c30e494 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java @@ -19,26 +19,27 @@ package org.elasticsearch.search.aggregations.metrics.stats.extended; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import java.io.IOException; import java.util.Objects; public class ExtendedStatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final ExtendedStatsAggregatorBuilder PROTOTYPE = new ExtendedStatsAggregatorBuilder(""); + public static final String NAME = InternalExtendedStats.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); private double sigma = 2.0; @@ -46,6 +47,24 @@ public class ExtendedStatsAggregatorBuilder super(name, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); } + /** + * Read from a stream. + */ + public ExtendedStatsAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + sigma = in.readDouble(); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeDouble(sigma); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + public ExtendedStatsAggregatorBuilder sigma(double sigma) { if (sigma < 0.0) { throw new IllegalArgumentException("[sigma] must be greater than or equal to 0. Found [" + sigma + "] in [" + name + "]"); @@ -64,19 +83,6 @@ public class ExtendedStatsAggregatorBuilder return new ExtendedStatsAggregatorFactory(name, type, config, sigma, context, parent, subFactoriesBuilder, metaData); } - @Override - protected ExtendedStatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregatorBuilder(name); - factory.sigma = in.readDouble(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeDouble(sigma); - } - @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { builder.field(ExtendedStatsAggregator.SIGMA_FIELD.getPreferredName(), sigma); @@ -93,4 +99,9 @@ public class ExtendedStatsAggregatorBuilder ExtendedStatsAggregatorBuilder other = (ExtendedStatsAggregatorBuilder) obj; return Objects.equals(sigma, other.sigma); } + + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java index faae604111a..76e6beac2da 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.metrics.stats.extended; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; @@ -38,11 +37,6 @@ public class ExtendedStatsParser extends NumericValuesSourceParser { super(true, true, false); } - @Override - public String type() { - return InternalExtendedStats.TYPE.name(); - } - @Override protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser, ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException { @@ -65,9 +59,4 @@ public class ExtendedStatsParser extends NumericValuesSourceParser { } return factory; } - - @Override - public AggregatorBuilder getFactoryPrototypes() { - return ExtendedStatsAggregatorBuilder.PROTOTYPE; - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java index 17671d9ffa3..6f83f0f64f1 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java @@ -19,46 +19,53 @@ package org.elasticsearch.search.aggregations.metrics.sum; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import java.io.IOException; public class SumAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final SumAggregatorBuilder PROTOTYPE = new SumAggregatorBuilder(""); + public static final String NAME = InternalSum.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public SumAggregatorBuilder(String name) { super(name, InternalSum.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); } + /** + * Read from a stream. + */ + public SumAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalSum.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + @Override protected SumAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { return new SumAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); } - @Override - protected ValuesSourceAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new SumAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { return builder; @@ -73,4 +80,9 @@ public class SumAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly protected boolean innerEquals(Object obj) { return true; } + + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java index 92664c9a6d8..7971adba4eb 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.metrics.sum; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; @@ -38,11 +37,6 @@ public class SumParser extends NumericValuesSourceParser { super(true, true, false); } - @Override - public String type() { - return InternalSum.TYPE.name(); - } - @Override protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser, ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException { @@ -54,9 +48,4 @@ public class SumParser extends NumericValuesSourceParser { ValueType targetValueType, Map otherOptions) { return new SumAggregatorBuilder(aggregationName); } - - @Override - public AggregatorBuilder getFactoryPrototypes() { - return SumAggregatorBuilder.PROTOTYPE; - } }