|
@@ -20,7 +20,7 @@ package org.elasticsearch.search.aggregations;
|
|
|
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
-import org.elasticsearch.common.io.stream.Streamable;
|
|
|
+import org.elasticsearch.common.io.stream.Writeable;
|
|
|
import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext;
|
|
|
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
|
|
import org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator;
|
|
@@ -34,14 +34,13 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
-import static java.util.Collections.emptyMap;
|
|
|
-
|
|
|
/**
|
|
|
* An internal implementation of {@link Aggregations}.
|
|
|
*/
|
|
|
-public final class InternalAggregations extends Aggregations implements Streamable {
|
|
|
+public final class InternalAggregations extends Aggregations implements Writeable {
|
|
|
+
|
|
|
+ public static final InternalAggregations EMPTY = new InternalAggregations(Collections.emptyList());
|
|
|
|
|
|
- public static final InternalAggregations EMPTY = new InternalAggregations();
|
|
|
private static final Comparator<InternalAggregation> INTERNAL_AGG_COMPARATOR = (agg1, agg2) -> {
|
|
|
if (agg1.isMapped() == agg2.isMapped()) {
|
|
|
return 0;
|
|
@@ -52,16 +51,14 @@ public final class InternalAggregations extends Aggregations implements Streamab
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- private List<SiblingPipelineAggregator> topLevelPipelineAggregators = Collections.emptyList();
|
|
|
-
|
|
|
- private InternalAggregations() {
|
|
|
- }
|
|
|
+ private final List<SiblingPipelineAggregator> topLevelPipelineAggregators;
|
|
|
|
|
|
/**
|
|
|
* Constructs a new aggregation.
|
|
|
*/
|
|
|
public InternalAggregations(List<InternalAggregation> aggregations) {
|
|
|
super(aggregations);
|
|
|
+ this.topLevelPipelineAggregators = Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -72,6 +69,19 @@ public final class InternalAggregations extends Aggregations implements Streamab
|
|
|
this.topLevelPipelineAggregators = Objects.requireNonNull(topLevelPipelineAggregators);
|
|
|
}
|
|
|
|
|
|
+ public InternalAggregations(StreamInput in) throws IOException {
|
|
|
+ super(in.readList(stream -> in.readNamedWriteable(InternalAggregation.class)));
|
|
|
+ this.topLevelPipelineAggregators = in.readList(
|
|
|
+ stream -> (SiblingPipelineAggregator)in.readNamedWriteable(PipelineAggregator.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ public void writeTo(StreamOutput out) throws IOException {
|
|
|
+ out.writeNamedWriteableList((List<InternalAggregation>)aggregations);
|
|
|
+ out.writeNamedWriteableList(topLevelPipelineAggregators);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns the top-level pipeline aggregators.
|
|
|
* Note that top-level pipeline aggregators become normal aggregation once the final reduction has been performed, after which they
|
|
@@ -86,8 +96,7 @@ public final class InternalAggregations extends Aggregations implements Streamab
|
|
|
* {@link InternalAggregations} object found in the list.
|
|
|
* Note that top-level pipeline aggregators are reduced only as part of the final reduction phase, otherwise they are left untouched.
|
|
|
*/
|
|
|
- public static InternalAggregations reduce(List<InternalAggregations> aggregationsList,
|
|
|
- ReduceContext context) {
|
|
|
+ public static InternalAggregations reduce(List<InternalAggregations> aggregationsList, ReduceContext context) {
|
|
|
if (aggregationsList.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
@@ -123,27 +132,4 @@ public final class InternalAggregations extends Aggregations implements Streamab
|
|
|
}
|
|
|
return new InternalAggregations(reducedAggregations, topLevelPipelineAggregators);
|
|
|
}
|
|
|
-
|
|
|
- public static InternalAggregations readAggregations(StreamInput in) throws IOException {
|
|
|
- InternalAggregations result = new InternalAggregations();
|
|
|
- result.readFrom(in);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void readFrom(StreamInput in) throws IOException {
|
|
|
- aggregations = in.readList(stream -> in.readNamedWriteable(InternalAggregation.class));
|
|
|
- if (aggregations.isEmpty()) {
|
|
|
- aggregationsAsMap = emptyMap();
|
|
|
- }
|
|
|
- this.topLevelPipelineAggregators = in.readList(
|
|
|
- stream -> (SiblingPipelineAggregator)in.readNamedWriteable(PipelineAggregator.class));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- public void writeTo(StreamOutput out) throws IOException {
|
|
|
- out.writeNamedWriteableList((List<InternalAggregation>)aggregations);
|
|
|
- out.writeNamedWriteableList(topLevelPipelineAggregators);
|
|
|
- }
|
|
|
}
|