Cut percentiles and percentile_ranks to registerAggregation

and remove their PROTOTYPEs.

Relates to #17085
This commit is contained in:
Nik Everett 2016-04-15 12:42:29 -04:00
parent c5bad1d93f
commit f6d141a29c
5 changed files with 79 additions and 77 deletions

View File

@ -170,7 +170,9 @@ import org.elasticsearch.search.aggregations.metrics.max.InternalMax;
import org.elasticsearch.search.aggregations.metrics.max.MaxParser;
import org.elasticsearch.search.aggregations.metrics.min.InternalMin;
import org.elasticsearch.search.aggregations.metrics.min.MinParser;
import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregatorBuilder;
import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksParser;
import org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregatorBuilder;
import org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesParser;
import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentileRanks;
import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentiles;
@ -461,8 +463,10 @@ public class SearchModule extends AbstractModule {
registerAggregatorParser(new StatsParser());
registerAggregatorParser(new ExtendedStatsParser());
registerAggregation(ValueCountAggregatorBuilder::new, new ValueCountParser(), ValueCountAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregatorParser(new PercentilesParser());
registerAggregatorParser(new PercentileRanksParser());
registerAggregation(PercentilesAggregatorBuilder::new, new PercentilesParser(),
PercentilesAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(PercentileRanksAggregatorBuilder::new, new PercentileRanksParser(),
PercentileRanksAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(CardinalityAggregatorBuilder::new, new CardinalityParser(),
CardinalityAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(GlobalAggregatorBuilder::new, GlobalAggregatorBuilder::parse, GlobalAggregatorBuilder.AGGREGATION_NAME_FIELD);

View File

@ -19,30 +19,31 @@
package org.elasticsearch.search.aggregations.metrics.percentiles;
import org.elasticsearch.common.ParseField;
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.AggregatorFactory;
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.HDRPercentileRanksAggregatorFactory;
import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentileRanks;
import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.TDigestPercentileRanksAggregatorFactory;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder.LeafOnly;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder.LeafOnly;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
public class PercentileRanksAggregatorBuilder extends LeafOnly<ValuesSource.Numeric, PercentileRanksAggregatorBuilder> {
static final PercentileRanksAggregatorBuilder PROTOTYPE = new PercentileRanksAggregatorBuilder("");
public static final String NAME = InternalTDigestPercentileRanks.TYPE.name();
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
private double[] values;
private PercentilesMethod method = PercentilesMethod.TDIGEST;
@ -54,6 +55,32 @@ public class PercentileRanksAggregatorBuilder extends LeafOnly<ValuesSource.Nume
super(name, InternalTDigestPercentileRanks.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
}
/**
* Read from a stream.
*/
public PercentileRanksAggregatorBuilder(StreamInput in) throws IOException {
super(in, InternalTDigestPercentileRanks.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
values = in.readDoubleArray();
keyed = in.readBoolean();
numberOfSignificantValueDigits = in.readVInt();
compression = in.readDouble();
method = PercentilesMethod.TDIGEST.readFrom(in);
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
out.writeDoubleArray(values);
out.writeBoolean(keyed);
out.writeVInt(numberOfSignificantValueDigits);
out.writeDouble(compression);
method.writeTo(out);
}
@Override
protected boolean usesNewStyleSerialization() {
return true;
}
/**
* Set the values to compute percentiles from.
*/
@ -157,27 +184,6 @@ public class PercentileRanksAggregatorBuilder extends LeafOnly<ValuesSource.Nume
}
}
@Override
protected PercentileRanksAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
PercentileRanksAggregatorBuilder factory = new PercentileRanksAggregatorBuilder(name);
factory.values = in.readDoubleArray();
factory.keyed = in.readBoolean();
factory.numberOfSignificantValueDigits = in.readVInt();
factory.compression = in.readDouble();
factory.method = PercentilesMethod.TDIGEST.readFrom(in);
return factory;
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
out.writeDoubleArray(values);
out.writeBoolean(keyed);
out.writeVInt(numberOfSignificantValueDigits);
out.writeDouble(compression);
method.writeTo(out);
}
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(PercentileRanksParser.VALUES_FIELD.getPreferredName(), values);
@ -226,4 +232,9 @@ public class PercentileRanksAggregatorBuilder extends LeafOnly<ValuesSource.Nume
throw new IllegalStateException("Illegal method [" + method.getName() + "]");
}
}
@Override
public String getWriteableName() {
return NAME;
}
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics.percentiles;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentileRanks;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
@ -34,11 +33,6 @@ public class PercentileRanksParser extends AbstractPercentilesParser {
super(false);
}
@Override
public String type() {
return InternalTDigestPercentileRanks.TYPE.name();
}
@Override
protected ParseField keysField() {
return VALUES_FIELD;
@ -65,10 +59,4 @@ public class PercentileRanksParser extends AbstractPercentilesParser {
}
return factory;
}
@Override
public PercentileRanksAggregatorBuilder getFactoryPrototypes() {
return PercentileRanksAggregatorBuilder.PROTOTYPE;
}
}

View File

@ -19,11 +19,12 @@
package org.elasticsearch.search.aggregations.metrics.percentiles;
import org.elasticsearch.common.ParseField;
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.AggregatorFactory;
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.HDRPercentilesAggregatorFactory;
import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles;
import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.TDigestPercentilesAggregatorFactory;
@ -31,18 +32,18 @@ import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder.LeafOnly;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
public class PercentilesAggregatorBuilder extends LeafOnly<ValuesSource.Numeric, PercentilesAggregatorBuilder> {
static final PercentilesAggregatorBuilder PROTOTYPE = new PercentilesAggregatorBuilder("");
public static final String NAME = InternalTDigestPercentiles.TYPE.name();
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
private double[] percents = PercentilesParser.DEFAULT_PERCENTS;
private PercentilesMethod method = PercentilesMethod.TDIGEST;
@ -54,6 +55,32 @@ public class PercentilesAggregatorBuilder extends LeafOnly<ValuesSource.Numeric,
super(name, InternalTDigestPercentiles.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
}
/**
* Read from a stream.
*/
public PercentilesAggregatorBuilder(StreamInput in) throws IOException {
super(in, InternalTDigestPercentiles.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
percents = in.readDoubleArray();
keyed = in.readBoolean();
numberOfSignificantValueDigits = in.readVInt();
compression = in.readDouble();
method = PercentilesMethod.TDIGEST.readFrom(in);
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
out.writeDoubleArray(percents);
out.writeBoolean(keyed);
out.writeVInt(numberOfSignificantValueDigits);
out.writeDouble(compression);
method.writeTo(out);
}
@Override
protected boolean usesNewStyleSerialization() {
return true;
}
/**
* Set the values to compute percentiles from.
*/
@ -157,27 +184,6 @@ public class PercentilesAggregatorBuilder extends LeafOnly<ValuesSource.Numeric,
}
}
@Override
protected PercentilesAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
ValueType targetValueType, StreamInput in) throws IOException {
PercentilesAggregatorBuilder factory = new PercentilesAggregatorBuilder(name);
factory.percents = in.readDoubleArray();
factory.keyed = in.readBoolean();
factory.numberOfSignificantValueDigits = in.readVInt();
factory.compression = in.readDouble();
factory.method = PercentilesMethod.TDIGEST.readFrom(in);
return factory;
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
out.writeDoubleArray(percents);
out.writeBoolean(keyed);
out.writeVInt(numberOfSignificantValueDigits);
out.writeDouble(compression);
method.writeTo(out);
}
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(PercentilesParser.PERCENTS_FIELD.getPreferredName(), percents);
@ -226,4 +232,9 @@ public class PercentilesAggregatorBuilder extends LeafOnly<ValuesSource.Numeric,
throw new IllegalStateException("Illegal method [" + method.getName() + "]");
}
}
@Override
public String getWriteableName() {
return NAME;
}
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics.percentiles;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles;
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
@ -36,11 +35,6 @@ public class PercentilesParser extends AbstractPercentilesParser {
public final static double[] DEFAULT_PERCENTS = new double[] { 1, 5, 25, 50, 75, 95, 99 };
@Override
public String type() {
return InternalTDigestPercentiles.TYPE.name();
}
@Override
protected ParseField keysField() {
return PERCENTS_FIELD;
@ -67,10 +61,4 @@ public class PercentilesParser extends AbstractPercentilesParser {
}
return factory;
}
@Override
public PercentilesAggregatorBuilder getFactoryPrototypes() {
return PercentilesAggregatorBuilder.PROTOTYPE;
}
}