Migrate sampler and missing aggregations to NamedWriteable

This is another step down the path to removing aggregation's special
"streams" which reimplement NamedWriteable.
This commit is contained in:
Nik Everett 2016-07-04 22:49:24 -04:00
parent d83e1cccac
commit 7da753a4d7
7 changed files with 45 additions and 91 deletions

View File

@ -551,13 +551,16 @@ public class SearchModule extends AbstractModule {
CardinalityAggregationBuilder.AGGREGATION_NAME_FIELD).addResultReader(InternalCardinality::new));
registerAggregation(new AggregationSpec(GlobalAggregationBuilder::new, GlobalAggregationBuilder::parse,
GlobalAggregationBuilder.AGGREGATION_NAME_FIELD).addResultReader(InternalGlobal::new));
registerAggregation(MissingAggregationBuilder::new, new MissingParser(), MissingAggregationBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(
new AggregationSpec(MissingAggregationBuilder::new, new MissingParser(), MissingAggregationBuilder.AGGREGATION_NAME_FIELD)
.addResultReader(InternalMissing::new));
registerAggregation(new AggregationSpec(FilterAggregationBuilder::new, FilterAggregationBuilder::parse,
FilterAggregationBuilder.AGGREGATION_NAME_FIELD).addResultReader(InternalFilter::new));
registerAggregation(new AggregationSpec(FiltersAggregationBuilder::new, FiltersAggregationBuilder::parse,
FiltersAggregationBuilder.AGGREGATION_NAME_FIELD).addResultReader(InternalFilters::new));
registerAggregation(SamplerAggregationBuilder::new, SamplerAggregationBuilder::parse,
SamplerAggregationBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(new AggregationSpec(SamplerAggregationBuilder::new, SamplerAggregationBuilder::parse,
SamplerAggregationBuilder.AGGREGATION_NAME_FIELD).addResultReader(InternalSampler.NAME, InternalSampler::new)
.addResultReader(UnmappedSampler.NAME, UnmappedSampler::new));
registerAggregation(DiversifiedAggregationBuilder::new, new DiversifiedSamplerParser(),
DiversifiedAggregationBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(TermsAggregationBuilder::new, new TermsParser(), TermsAggregationBuilder.AGGREGATION_NAME_FIELD);
@ -767,9 +770,6 @@ public class SearchModule extends AbstractModule {
static {
// buckets
InternalSampler.registerStreams();
UnmappedSampler.registerStreams();
InternalMissing.registerStreams();
StringTerms.registerStreams();
LongTerms.registerStreams();
SignificantStringTerms.registerStreams();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.missing;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.search.aggregations.AggregationStreams;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
@ -28,37 +27,21 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
*
*/
public class InternalMissing extends InternalSingleBucketAggregation implements Missing {
public static final Type TYPE = new Type("missing");
public static final AggregationStreams.Stream STREAM = new AggregationStreams.Stream() {
@Override
public InternalMissing readResult(StreamInput in) throws IOException {
InternalMissing missing = new InternalMissing();
missing.readFrom(in);
return missing;
}
};
public static void registerStreams() {
AggregationStreams.registerStream(STREAM, TYPE.stream());
}
InternalMissing() {
}
InternalMissing(String name, long docCount, InternalAggregations aggregations, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
super(name, docCount, aggregations, pipelineAggregators, metaData);
}
/**
* Read from a stream.
*/
public InternalMissing(StreamInput in) throws IOException {
super(in);
}
@Override
public Type type() {
return TYPE;
public String getWriteableName() {
return MissingAggregationBuilder.NAME;
}
@Override

View File

@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.InternalAggregation.Type;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
@ -36,18 +37,19 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
public class MissingAggregationBuilder extends ValuesSourceAggregationBuilder<ValuesSource, MissingAggregationBuilder> {
public static final String NAME = InternalMissing.TYPE.name();
public static final String NAME = "missing";
public static final Type TYPE = new Type(NAME);
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
public MissingAggregationBuilder(String name, ValueType targetValueType) {
super(name, InternalMissing.TYPE, ValuesSourceType.ANY, targetValueType);
super(name, TYPE, ValuesSourceType.ANY, targetValueType);
}
/**
* Read from a stream.
*/
public MissingAggregationBuilder(StreamInput in) throws IOException {
super(in, InternalMissing.TYPE, ValuesSourceType.ANY);
super(in, TYPE, ValuesSourceType.ANY);
}
@Override

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.sampler;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.search.aggregations.AggregationStreams;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
@ -28,36 +27,22 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
*
*/
public class InternalSampler extends InternalSingleBucketAggregation implements Sampler {
public static final Type TYPE = new Type("sampler");
public static final AggregationStreams.Stream STREAM = new AggregationStreams.Stream() {
@Override
public InternalSampler readResult(StreamInput in) throws IOException {
InternalSampler result = new InternalSampler();
result.readFrom(in);
return result;
}
};
public static void registerStreams() {
AggregationStreams.registerStream(STREAM, TYPE.stream());
}
InternalSampler() {
} // for serialization
public static final String NAME = "mapped_sampler";
InternalSampler(String name, long docCount, InternalAggregations subAggregations, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
super(name, docCount, subAggregations, pipelineAggregators, metaData);
}
/**
* Read from a stream.
*/
public InternalSampler(StreamInput in) throws IOException {
super(in);
}
@Override
public Type type() {
return TYPE;
public String getWriteableName() {
return NAME;
}
@Override

View File

@ -29,13 +29,15 @@ import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation.Type;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import java.io.IOException;
import java.util.Objects;
public class SamplerAggregationBuilder extends AbstractAggregationBuilder<SamplerAggregationBuilder> {
public static final String NAME = InternalSampler.TYPE.name();
public static final String NAME = "sampler";
private static final Type TYPE = new Type(NAME);
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
public static final int DEFAULT_SHARD_SAMPLE_SIZE = 100;
@ -43,14 +45,14 @@ public class SamplerAggregationBuilder extends AbstractAggregationBuilder<Sample
private int shardSize = DEFAULT_SHARD_SAMPLE_SIZE;
public SamplerAggregationBuilder(String name) {
super(name, InternalSampler.TYPE);
super(name, TYPE);
}
/**
* Read from a stream.
*/
public SamplerAggregationBuilder(StreamInput in) throws IOException {
super(in, InternalSampler.TYPE);
super(in, TYPE);
shardSize = in.readVInt();
}

View File

@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.bucket.sampler;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.aggregations.AggregationStreams;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
@ -29,37 +28,23 @@ import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
*
*/
public class UnmappedSampler extends InternalSampler {
public static final Type TYPE = new Type("sampler", "umsampler");
public static final AggregationStreams.Stream STREAM = new AggregationStreams.Stream() {
@Override
public UnmappedSampler readResult(StreamInput in) throws IOException {
UnmappedSampler sampler = new UnmappedSampler();
sampler.readFrom(in);
return sampler;
}
};
public static void registerStreams() {
AggregationStreams.registerStream(STREAM, TYPE.stream());
}
UnmappedSampler() {
}
public static final String NAME = "unmapped_sampler";
public UnmappedSampler(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) {
super(name, 0, InternalAggregations.EMPTY, pipelineAggregators, metaData);
}
/**
* Read from a stream.
*/
public UnmappedSampler(StreamInput in) throws IOException {
super(in);
}
@Override
public Type type() {
return TYPE;
public String getWriteableName() {
return NAME;
}
@Override

View File

@ -40,9 +40,6 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.notNullValue;
/**
*
*/
@ESIntegTestCase.SuiteScopeTestCase
public class MissingIT extends ESIntegTestCase {