Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public interface Parser {
* @return an empty {@link AggregatorFactory} instance for this parser
* that can be used for deserialization
*/
AggregatorFactory getFactoryPrototype();
AggregatorFactory[] getFactoryPrototypes();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.ObjectArray;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.aggregations.InternalAggregation.Type;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.internal.SearchContext.Lifetime;
Expand All @@ -44,7 +45,7 @@
public abstract class AggregatorFactory extends ToXContentToBytes implements NamedWriteable<AggregatorFactory> {

protected String name;
protected String type;
protected Type type;
protected AggregatorFactory parent;
protected AggregatorFactories factories = AggregatorFactories.EMPTY;
protected Map<String, Object> metaData;
Expand All @@ -56,7 +57,7 @@ public abstract class AggregatorFactory extends ToXContentToBytes implements Nam
* @param name The aggregation name
* @param type The aggregation type
*/
public AggregatorFactory(String name, String type) {
public AggregatorFactory(String name, Type type) {
this.name = name;
this.type = type;
}
Expand All @@ -74,7 +75,7 @@ public final void init(AggregationContext context) {
/**
* Allows the {@link AggregatorFactory} to initialize any state prior to
* using it to create {@link Aggregator}s.
*
*
* @param context
* the {@link AggregationContext} to use during initialization.
*/
Expand Down Expand Up @@ -170,7 +171,7 @@ public final XContentBuilder toXContent(XContentBuilder builder, Params params)
if (this.metaData != null) {
builder.field("meta", this.metaData);
}
builder.field(type);
builder.field(type.name());
internalXContent(builder, params);

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

@Override
public String getWriteableName() {
return type;
return type.stream().toUtf8();
}

public String getType() {
return type.name();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ public AggregatorParsers(Set<Aggregator.Parser> aggParsers, Set<PipelineAggregat
Map<String, Aggregator.Parser> aggParsersBuilder = new HashMap<>(aggParsers.size());
for (Aggregator.Parser parser : aggParsers) {
aggParsersBuilder.put(parser.type(), parser);
AggregatorFactory factoryPrototype = parser.getFactoryPrototype();
AggregatorFactory[] factoryPrototypes = parser.getFactoryPrototypes();
// NORELEASE remove this check when agg refactoring complete
if (factoryPrototype != null) {
namedWriteableRegistry.registerPrototype(AggregatorFactory.class, factoryPrototype);
if (factoryPrototypes != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we return an array, I'd rather like to enforce it to be non-null: if you don't want to register something you can provide an empty array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I absolutely agree. This null check is only here while there are Aggregations which are not refactored. Once the aggregation refactoring is complete this check will be removed and the method will need to return a non-null value (see NORELEASE comment above). I could go through and make all non refactored aggregation return an empty array for this method but I wanted to leave them returning null so that if this check is removed before all aggregations have been refactored we will be alerted to the factor we have not refactored one or more of the aggregations as the node will throw a NPE on start up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops, the change made me miss the norelease comment above!

for (AggregatorFactory factoryPrototype : factoryPrototypes) {
namedWriteableRegistry.registerPrototype(AggregatorFactory.class, factoryPrototype);
}
}
}
this.aggParsers = unmodifiableMap(aggParsersBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.elasticsearch.search.aggregations.bucket.children;

import org.apache.lucene.search.Query;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.search.SearchParseException;
import org.elasticsearch.search.aggregations.Aggregator;
Expand Down Expand Up @@ -70,7 +69,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource.B
private Query childFilter;

public Factory(String name, String childType) {
super(name, InternalChildren.TYPE.name(), new ValuesSourceParser.Input<ValuesSource.Bytes.WithOrdinals.ParentChild>());
super(name, InternalChildren.TYPE, new ValuesSourceParser.Input<ValuesSource.Bytes.WithOrdinals.ParentChild>());
this.childType = childType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static class Factory extends AggregatorFactory {
private final Query filter;

public Factory(String name, Query filter) {
super(name, InternalFilter.TYPE.name());
super(name, InternalFilter.TYPE);
this.filter = filter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static class Factory extends AggregatorFactory {
private String otherBucketKey;

public Factory(String name, List<KeyedFilter> filters, boolean keyed, String otherBucketKey) {
super(name, InternalFilters.TYPE.name());
super(name, InternalFilters.TYPE);
this.filters = filters;
this.keyed = keyed;
this.otherBucketKey = otherBucketKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public String type() {
return InternalGeoHashGrid.TYPE.name();
}
@Override
public AggregatorFactory getFactoryPrototype() {
return new GeoGridFactory(null);
public AggregatorFactory[] getFactoryPrototypes() {
return new AggregatorFactory[] { new GeoGridFactory(null) };
}

@Override
Expand Down Expand Up @@ -121,7 +121,7 @@ public static class GeoGridFactory extends ValuesSourceAggregatorFactory<ValuesS
private int shardSize = -1;

public GeoGridFactory(String name) {
super(name, InternalGeoHashGrid.TYPE.name(), ValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
super(name, InternalGeoHashGrid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT);
}

public void precision(int precision) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public InternalAggregation buildEmptyAggregation() {
public static class Factory extends AggregatorFactory {

public Factory(String name) {
super(name, InternalGlobal.TYPE.name());
super(name, InternalGlobal.TYPE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se
}

@Override
public AggregatorFactory getFactoryPrototype() {
return new GlobalAggregator.Factory(null);
public AggregatorFactory[] getFactoryPrototypes() {
return new AggregatorFactory[] { new GlobalAggregator.Factory(null) };
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected long parseStringOffset(String offset) throws IOException {
}

@Override
public AggregatorFactory getFactoryPrototype() {
return HistogramAggregator.DateHistogramFactory.PROTOTYPE;
public AggregatorFactory[] getFactoryPrototypes() {
return new AggregatorFactory[] { HistogramAggregator.DateHistogramFactory.PROTOTYPE };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static InternalOrder resolveOrder(String key, boolean asc) {
}

@Override
public AggregatorFactory getFactoryPrototype() {
return HistogramAggregator.Factory.PROTOTYPE;
public AggregatorFactory[] getFactoryPrototypes() {
return new AggregatorFactory[] { HistogramAggregator.Factory.PROTOTYPE };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ static class Factory extends InternalHistogram.Factory<InternalDateHistogram.Buc
}

@Override
public String type() {
return TYPE.name();
public Type type() {
return TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ public static class Factory<B extends InternalHistogram.Bucket> {
protected Factory() {
}

public String type() {
return TYPE.name();
public Type type() {
return TYPE;
}

public ValueType valueType() {
Expand Down Expand Up @@ -514,7 +514,7 @@ protected static <B extends InternalHistogram.Bucket> Factory<B> resolveFactory(

@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeString(factory.type());
out.writeString(factory.type().name());
InternalOrder.Streams.writeOrder(order, out);
out.writeVLong(minDocCount);
if (minDocCount == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public InternalAggregation buildEmptyAggregation() {
public static class Factory extends ValuesSourceAggregatorFactory<ValuesSource> {

public Factory(String name, ValuesSourceParser.Input valueSourceInput) {
super(name, InternalMissing.TYPE.name(), valueSourceInput);
super(name, InternalMissing.TYPE, valueSourceInput);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void collect(int parentDoc, long bucket) throws IOException {
}
};
}

@Override
public InternalAggregation buildAggregation(long owningBucketOrdinal) throws IOException {
return new InternalNested(name, bucketDocCount(owningBucketOrdinal), bucketAggregations(owningBucketOrdinal), pipelineAggregators(),
Expand Down Expand Up @@ -142,7 +142,7 @@ public static class Factory extends AggregatorFactory {
private final String path;

public Factory(String name, String path) {
super(name, InternalNested.TYPE.name());
super(name, InternalNested.TYPE);
this.path = path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public void collect(int childDoc, long bucket) throws IOException {
// fast forward to retrieve the parentDoc this childDoc belongs to
final int parentDoc = parentDocs.nextSetBit(childDoc);
assert childDoc <= parentDoc && parentDoc != DocIdSetIterator.NO_MORE_DOCS;
int keySlot = bucketOrdToLastCollectedParentDoc.indexOf(bucket);

int keySlot = bucketOrdToLastCollectedParentDoc.indexOf(bucket);
if (bucketOrdToLastCollectedParentDoc.indexExists(keySlot)) {
int lastCollectedParentDoc = bucketOrdToLastCollectedParentDoc.indexGet(keySlot);
if (parentDoc > lastCollectedParentDoc) {
Expand Down Expand Up @@ -124,7 +124,7 @@ public static class Factory extends AggregatorFactory {
private final String path;

public Factory(String name, String path) {
super(name, InternalReverseNested.TYPE.name());
super(name, InternalReverseNested.TYPE);
this.path = path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ public void writeTo(StreamOutput out) throws IOException {

public static class Factory<B extends Bucket, R extends InternalRange<B, R>> {

public String type() {
return TYPE.name();
public Type type() {
return TYPE;
}

public R create(String name, List<B> ranges, ValueFormatter formatter, boolean keyed, List<PipelineAggregator> pipelineAggregators,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public AggregatorFactory parse(String aggregationName, XContentParser parser, Se

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ ValueFormatter formatter() {
public static class Factory extends InternalRange.Factory<InternalDateRange.Bucket, InternalDateRange> {

@Override
public String type() {
return TYPE.name();
public Type type() {
return TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public SortedBinaryDocValues bytesValues(LeafReaderContext ctx) {

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ ValueFormatter formatter() {
public static class Factory extends InternalRange.Factory<InternalGeoDistance.Bucket, InternalGeoDistance> {

@Override
public String type() {
return TYPE.name();
public Type type() {
return TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ boolean keyed() {
public static class Factory extends InternalRange.Factory<InternalIPv4Range.Bucket, InternalIPv4Range> {

@Override
public String type() {
return TYPE.name();
public Type type() {
return TYPE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static void parseMaskRange(String cidr, RangeAggregator.Range range, Str

// NORELEASE implement this method when refactoring this aggregation
@Override
public AggregatorFactory getFactoryPrototype() {
public AggregatorFactory[] getFactoryPrototypes() {
return null;
}

Expand Down
Loading