Skip to content

Commit 328e332

Browse files
committed
Aggregations Refactor: Refactor Percentiles and Percentile Ranks Aggregation
1 parent af625f0 commit 328e332

File tree

73 files changed

+898
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+898
-288
lines changed

core/src/main/java/org/elasticsearch/search/aggregations/Aggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public interface Parser {
6565
* @return an empty {@link AggregatorFactory} instance for this parser
6666
* that can be used for deserialization
6767
*/
68-
AggregatorFactory getFactoryPrototype();
68+
AggregatorFactory[] getFactoryPrototypes();
6969
}
7070

7171
/**

core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactory.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.common.util.BigArrays;
3030
import org.elasticsearch.common.util.ObjectArray;
3131
import org.elasticsearch.common.xcontent.XContentBuilder;
32+
import org.elasticsearch.search.aggregations.InternalAggregation.Type;
3233
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
3334
import org.elasticsearch.search.aggregations.support.AggregationContext;
3435
import org.elasticsearch.search.internal.SearchContext.Lifetime;
@@ -44,7 +45,7 @@
4445
public abstract class AggregatorFactory extends ToXContentToBytes implements NamedWriteable<AggregatorFactory> {
4546

4647
protected String name;
47-
protected String type;
48+
protected Type type;
4849
protected AggregatorFactory parent;
4950
protected AggregatorFactories factories = AggregatorFactories.EMPTY;
5051
protected Map<String, Object> metaData;
@@ -56,7 +57,7 @@ public abstract class AggregatorFactory extends ToXContentToBytes implements Nam
5657
* @param name The aggregation name
5758
* @param type The aggregation type
5859
*/
59-
public AggregatorFactory(String name, String type) {
60+
public AggregatorFactory(String name, Type type) {
6061
this.name = name;
6162
this.type = type;
6263
}
@@ -74,7 +75,7 @@ public final void init(AggregationContext context) {
7475
/**
7576
* Allows the {@link AggregatorFactory} to initialize any state prior to
7677
* using it to create {@link Aggregator}s.
77-
*
78+
*
7879
* @param context
7980
* the {@link AggregationContext} to use during initialization.
8081
*/
@@ -170,7 +171,7 @@ public final XContentBuilder toXContent(XContentBuilder builder, Params params)
170171
if (this.metaData != null) {
171172
builder.field("meta", this.metaData);
172173
}
173-
builder.field(type);
174+
builder.field(type.name());
174175
internalXContent(builder, params);
175176

176177
if (factories != null && factories.count() > 0) {
@@ -189,7 +190,11 @@ protected XContentBuilder internalXContent(XContentBuilder builder, Params param
189190

190191
@Override
191192
public String getWriteableName() {
192-
return type;
193+
return type.stream().toUtf8();
194+
}
195+
196+
public String getType() {
197+
return type.name();
193198
}
194199

195200
/**

core/src/main/java/org/elasticsearch/search/aggregations/AggregatorParsers.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ public AggregatorParsers(Set<Aggregator.Parser> aggParsers, Set<PipelineAggregat
6060
Map<String, Aggregator.Parser> aggParsersBuilder = new HashMap<>(aggParsers.size());
6161
for (Aggregator.Parser parser : aggParsers) {
6262
aggParsersBuilder.put(parser.type(), parser);
63-
AggregatorFactory factoryPrototype = parser.getFactoryPrototype();
63+
AggregatorFactory[] factoryPrototypes = parser.getFactoryPrototypes();
6464
// NORELEASE remove this check when agg refactoring complete
65-
if (factoryPrototype != null) {
66-
namedWriteableRegistry.registerPrototype(AggregatorFactory.class, factoryPrototype);
65+
if (factoryPrototypes != null) {
66+
for (AggregatorFactory factoryPrototype : factoryPrototypes) {
67+
namedWriteableRegistry.registerPrototype(AggregatorFactory.class, factoryPrototype);
68+
}
6769
}
6870
}
6971
this.aggParsers = unmodifiableMap(aggParsersBuilder);

core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ChildrenParser.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.elasticsearch.search.aggregations.bucket.children;
2020

21-
import org.apache.lucene.search.Query;
2221
import org.elasticsearch.common.xcontent.XContentParser;
2322
import org.elasticsearch.search.SearchParseException;
2423
import org.elasticsearch.search.aggregations.Aggregator;
@@ -70,7 +69,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se
7069

7170
// NORELEASE implement this method when refactoring this aggregation
7271
@Override
73-
public AggregatorFactory getFactoryPrototype() {
72+
public AggregatorFactory[] getFactoryPrototypes() {
7473
return null;
7574
}
7675
}

core/src/main/java/org/elasticsearch/search/aggregations/bucket/children/ParentToChildrenAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource.B
201201
private Query childFilter;
202202

203203
public Factory(String name, String childType) {
204-
super(name, InternalChildren.TYPE.name(), new ValuesSourceParser.Input<ValuesSource.Bytes.WithOrdinals.ParentChild>());
204+
super(name, InternalChildren.TYPE, new ValuesSourceParser.Input<ValuesSource.Bytes.WithOrdinals.ParentChild>());
205205
this.childType = childType;
206206
}
207207

core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static class Factory extends AggregatorFactory {
8585
private final Query filter;
8686

8787
public Factory(String name, Query filter) {
88-
super(name, InternalFilter.TYPE.name());
88+
super(name, InternalFilter.TYPE);
8989
this.filter = filter;
9090
}
9191

core/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se
4646

4747
// NORELEASE implement this method when refactoring this aggregation
4848
@Override
49-
public AggregatorFactory getFactoryPrototype() {
49+
public AggregatorFactory[] getFactoryPrototypes() {
5050
return null;
5151
}
5252

core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static class Factory extends AggregatorFactory {
150150
private String otherBucketKey;
151151

152152
public Factory(String name, List<KeyedFilter> filters, boolean keyed, String otherBucketKey) {
153-
super(name, InternalFilters.TYPE.name());
153+
super(name, InternalFilters.TYPE);
154154
this.filters = filters;
155155
this.keyed = keyed;
156156
this.otherBucketKey = otherBucketKey;

core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se
119119

120120
// NORELEASE implement this method when refactoring this aggregation
121121
@Override
122-
public AggregatorFactory getFactoryPrototype() {
122+
public AggregatorFactory[] getFactoryPrototypes() {
123123
return null;
124124
}
125125

core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public String type() {
7272
return InternalGeoHashGrid.TYPE.name();
7373
}
7474
@Override
75-
public AggregatorFactory getFactoryPrototype() {
76-
return new GeoGridFactory(null);
75+
public AggregatorFactory[] getFactoryPrototypes() {
76+
return new AggregatorFactory[] { new GeoGridFactory(null) };
7777
}
7878

7979
@Override
@@ -121,7 +121,7 @@ public static class GeoGridFactory extends ValuesSourceAggregatorFactory<ValuesS
121121
private int shardSize = -1;
122122

123123
public GeoGridFactory(String name) {
124-
super(name, InternalGeoHashGrid.TYPE.name(), ValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
124+
super(name, InternalGeoHashGrid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
125125
}
126126

127127
public void precision(int precision) {

0 commit comments

Comments
 (0)