Cut avg aggregation to registerAggregation
and remove its PROTOTYPE Relates to #17085
This commit is contained in:
parent
b10c1f1939
commit
a36b6138d7
|
@ -148,6 +148,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.LongTerms;
|
|||
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsParser;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.UnmappedTerms;
|
||||
import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregatorBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.avg.AvgParser;
|
||||
import org.elasticsearch.search.aggregations.metrics.avg.InternalAvg;
|
||||
import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityParser;
|
||||
|
@ -442,7 +443,7 @@ public class SearchModule extends AbstractModule {
|
|||
|
||||
SignificanceHeuristicParserMapper significanceHeuristicParserMapper = new SignificanceHeuristicParserMapper(heuristicParsers);
|
||||
|
||||
registerAggregatorParser(new AvgParser());
|
||||
registerAggregation(AvgAggregatorBuilder::new, new AvgParser(), AvgAggregatorBuilder.AGGREGATION_NAME_FIELD);
|
||||
registerAggregatorParser(new SumParser());
|
||||
registerAggregatorParser(new MinParser());
|
||||
registerAggregatorParser(new MaxParser());
|
||||
|
|
|
@ -191,6 +191,7 @@ public abstract class AggregatorBuilder<AB extends AggregatorBuilder<AB>> extend
|
|||
@Override
|
||||
public String getWriteableName() {
|
||||
// NORELEASE remove this before 5.0.0GA - all builders will implement this method on their own.
|
||||
assert usesNewStyleSerialization() == false: "migrated aggregations should just return their NAME";
|
||||
return type.stream().toUtf8();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,47 +19,53 @@
|
|||
|
||||
package org.elasticsearch.search.aggregations.metrics.avg;
|
||||
|
||||
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 AvgAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly<ValuesSource.Numeric, AvgAggregatorBuilder> {
|
||||
|
||||
static final AvgAggregatorBuilder PROTOTYPE = new AvgAggregatorBuilder("");
|
||||
public static final String NAME = InternalAvg.TYPE.name();
|
||||
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public AvgAggregatorBuilder(String name) {
|
||||
super(name, InternalAvg.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public AvgAggregatorBuilder(StreamInput in) throws IOException {
|
||||
super(in, InternalAvg.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 AvgAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig<Numeric> config,
|
||||
AggregatorFactory<?> parent, Builder subFactoriesBuilder) throws IOException {
|
||||
return new AvgAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AvgAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
|
||||
ValueType targetValueType, StreamInput in) {
|
||||
return new AvgAggregatorBuilder(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 AvgAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly
|
|||
protected boolean innerEquals(Object obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return NAME;
|
||||
}
|
||||
}
|
|
@ -37,11 +37,6 @@ public class AvgParser extends NumericValuesSourceParser {
|
|||
super(true, true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return InternalAvg.TYPE.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser,
|
||||
ParseFieldMatcher parseFieldMatcher, Map<ParseField, Object> otherOptions) throws IOException {
|
||||
|
@ -53,10 +48,4 @@ public class AvgParser extends NumericValuesSourceParser {
|
|||
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
|
||||
return new AvgAggregatorBuilder(aggregationName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AvgAggregatorBuilder getFactoryPrototypes() {
|
||||
return AvgAggregatorBuilder.PROTOTYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.support;
|
|||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.index.fielddata.IndexFieldData;
|
||||
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
|
||||
|
@ -32,9 +31,9 @@ import org.elasticsearch.script.ScriptContext;
|
|||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.aggregations.AggregationInitializationException;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.InternalAggregation.Type;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
@ -57,6 +56,13 @@ public abstract class ValuesSourceAggregatorBuilder<VS extends ValuesSource, AB
|
|||
super(name, type, valuesSourceType, targetValueType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
protected LeafOnly(StreamInput in, Type type, ValuesSourceType valuesSourceType, ValueType targetValueType) throws IOException {
|
||||
super(in, type, valuesSourceType, targetValueType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AB subAggregations(Builder subFactories) {
|
||||
throw new AggregationInitializationException("Aggregator [" + name + "] of type [" + type + "] cannot accept sub-aggregations");
|
||||
|
@ -138,6 +144,9 @@ public abstract class ValuesSourceAggregatorBuilder<VS extends ValuesSource, AB
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write subclass's state to the stream.
|
||||
*/
|
||||
protected abstract void innerWriteTo(StreamOutput out) throws IOException;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Reference in New Issue