AggregatorFactories now stores reducers as well as aggregators
These reducers will be passed through from the AggregatorParser
This commit is contained in:
parent
c60bb4d73b
commit
ae76239b0a
|
@ -19,6 +19,7 @@
|
||||||
package org.elasticsearch.search.aggregations;
|
package org.elasticsearch.search.aggregations;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||||
|
import org.elasticsearch.search.aggregations.reducers.Reducer;
|
||||||
import org.elasticsearch.search.aggregations.support.AggregationContext;
|
import org.elasticsearch.search.aggregations.support.AggregationContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -35,13 +36,19 @@ public class AggregatorFactories {
|
||||||
public static final AggregatorFactories EMPTY = new Empty();
|
public static final AggregatorFactories EMPTY = new Empty();
|
||||||
|
|
||||||
private AggregatorFactory[] factories;
|
private AggregatorFactory[] factories;
|
||||||
|
private List<Reducer> reducers;
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
private AggregatorFactories(AggregatorFactory[] factories) {
|
private AggregatorFactories(AggregatorFactory[] factories, List<Reducer> reducers) {
|
||||||
this.factories = factories;
|
this.factories = factories;
|
||||||
|
this.reducers = reducers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Reducer> reducers() {
|
||||||
|
return reducers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Aggregator createAndRegisterContextAware(AggregationContext context, AggregatorFactory factory, Aggregator parent, boolean collectsFromSingleBucket) throws IOException {
|
private static Aggregator createAndRegisterContextAware(AggregationContext context, AggregatorFactory factory, Aggregator parent, boolean collectsFromSingleBucket) throws IOException {
|
||||||
|
@ -100,9 +107,10 @@ public class AggregatorFactories {
|
||||||
|
|
||||||
private static final AggregatorFactory[] EMPTY_FACTORIES = new AggregatorFactory[0];
|
private static final AggregatorFactory[] EMPTY_FACTORIES = new AggregatorFactory[0];
|
||||||
private static final Aggregator[] EMPTY_AGGREGATORS = new Aggregator[0];
|
private static final Aggregator[] EMPTY_AGGREGATORS = new Aggregator[0];
|
||||||
|
private static final List<Reducer> EMPTY_REDUCERS = new ArrayList<>();
|
||||||
|
|
||||||
private Empty() {
|
private Empty() {
|
||||||
super(EMPTY_FACTORIES);
|
super(EMPTY_FACTORIES, EMPTY_REDUCERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,6 +129,7 @@ public class AggregatorFactories {
|
||||||
|
|
||||||
private final Set<String> names = new HashSet<>();
|
private final Set<String> names = new HashSet<>();
|
||||||
private final List<AggregatorFactory> factories = new ArrayList<>();
|
private final List<AggregatorFactory> factories = new ArrayList<>();
|
||||||
|
private List<Reducer> reducers = new ArrayList<>();
|
||||||
|
|
||||||
public Builder add(AggregatorFactory factory) {
|
public Builder add(AggregatorFactory factory) {
|
||||||
if (!names.add(factory.name)) {
|
if (!names.add(factory.name)) {
|
||||||
|
@ -130,11 +139,16 @@ public class AggregatorFactories {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setReducers(List<Reducer> reducers) {
|
||||||
|
this.reducers = reducers;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public AggregatorFactories build() {
|
public AggregatorFactories build() {
|
||||||
if (factories.isEmpty()) {
|
if (factories.isEmpty()) {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
return new AggregatorFactories(factories.toArray(new AggregatorFactory[factories.size()]));
|
return new AggregatorFactories(factories.toArray(new AggregatorFactory[factories.size()]), this.reducers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.elasticsearch.search.aggregations.support.AggregationContext;
|
||||||
import org.elasticsearch.search.internal.SearchContext.Lifetime;
|
import org.elasticsearch.search.internal.SearchContext.Lifetime;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -41,7 +40,6 @@ public abstract class AggregatorFactory {
|
||||||
protected String type;
|
protected String type;
|
||||||
protected AggregatorFactory parent;
|
protected AggregatorFactory parent;
|
||||||
protected AggregatorFactories factories = AggregatorFactories.EMPTY;
|
protected AggregatorFactories factories = AggregatorFactories.EMPTY;
|
||||||
protected List<Reducer> reducers = Collections.emptyList();
|
|
||||||
protected Map<String, Object> metaData;
|
protected Map<String, Object> metaData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +95,7 @@ public abstract class AggregatorFactory {
|
||||||
* @return The created aggregator
|
* @return The created aggregator
|
||||||
*/
|
*/
|
||||||
public final Aggregator create(AggregationContext context, Aggregator parent, boolean collectsFromSingleBucket) throws IOException {
|
public final Aggregator create(AggregationContext context, Aggregator parent, boolean collectsFromSingleBucket) throws IOException {
|
||||||
return createInternal(context, parent, collectsFromSingleBucket, this.reducers, this.metaData);
|
return createInternal(context, parent, collectsFromSingleBucket, this.factories.reducers(), this.metaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doValidate() {
|
public void doValidate() {
|
||||||
|
@ -108,10 +106,6 @@ public abstract class AggregatorFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setReducers(List<Reducer> reducers) {
|
|
||||||
this.reducers = reducers;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method. Given an {@link AggregatorFactory} that creates {@link Aggregator}s that only know how
|
* Utility method. Given an {@link AggregatorFactory} that creates {@link Aggregator}s that only know how
|
||||||
|
|
Loading…
Reference in New Issue