Remove PROTOTYPE from histogram aggregations
This commit is contained in:
parent
b87fd54ba9
commit
f095e64825
|
@ -111,7 +111,9 @@ import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridParser;
|
|||
import org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid;
|
||||
import org.elasticsearch.search.aggregations.bucket.global.GlobalParser;
|
||||
import org.elasticsearch.search.aggregations.bucket.global.InternalGlobal;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramParser;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregatorBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.HistogramParser;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram;
|
||||
import org.elasticsearch.search.aggregations.bucket.missing.InternalMissing;
|
||||
|
@ -458,8 +460,9 @@ public class SearchModule extends AbstractModule {
|
|||
registerAggregatorParser(new RangeParser());
|
||||
registerAggregatorParser(new DateRangeParser());
|
||||
registerAggregatorParser(new IpRangeParser());
|
||||
registerAggregatorParser(new HistogramParser());
|
||||
registerAggregatorParser(new DateHistogramParser());
|
||||
registerAggregation(HistogramAggregatorBuilder::new, new HistogramParser(), HistogramAggregatorBuilder.AGGREGATION_NAME_FIELD);
|
||||
registerAggregation(DateHistogramAggregatorBuilder::new, new DateHistogramParser(),
|
||||
DateHistogramAggregatorBuilder.AGGREGATION_NAME_FIELD);
|
||||
registerAggregatorParser(new GeoDistanceParser());
|
||||
registerAggregatorParser(new GeoHashGridParser());
|
||||
registerAggregatorParser(new NestedParser());
|
||||
|
|
|
@ -23,10 +23,10 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.rounding.Rounding;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.search.aggregations.support.ValueType;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSource;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -40,10 +40,50 @@ public abstract class AbstractHistogramBuilder<AB extends AbstractHistogramBuild
|
|||
protected long minDocCount = 0;
|
||||
protected ExtendedBounds extendedBounds;
|
||||
|
||||
AbstractHistogramBuilder(String name, InternalHistogram.Factory<?> histogramFactory) {
|
||||
protected AbstractHistogramBuilder(String name, InternalHistogram.Factory<?> histogramFactory) {
|
||||
super(name, histogramFactory.type(), ValuesSourceType.NUMERIC, histogramFactory.valueType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
protected AbstractHistogramBuilder(StreamInput in, InternalHistogram.Factory<?> histogramFactory) throws IOException {
|
||||
super(in, histogramFactory.type(), ValuesSourceType.NUMERIC, histogramFactory.valueType());
|
||||
interval = in.readVLong();
|
||||
offset = in.readLong();
|
||||
if (in.readBoolean()) {
|
||||
order = InternalOrder.Streams.readOrder(in);
|
||||
}
|
||||
keyed = in.readBoolean();
|
||||
minDocCount = in.readVLong();
|
||||
if (in.readBoolean()) {
|
||||
extendedBounds = ExtendedBounds.readFrom(in);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerWriteTo(StreamOutput out) throws IOException {
|
||||
out.writeVLong(interval);
|
||||
out.writeLong(offset);
|
||||
boolean hasOrder = order != null;
|
||||
out.writeBoolean(hasOrder);
|
||||
if (hasOrder) {
|
||||
InternalOrder.Streams.writeOrder(order, out);
|
||||
}
|
||||
out.writeBoolean(keyed);
|
||||
out.writeVLong(minDocCount);
|
||||
boolean hasExtendedBounds = extendedBounds != null;
|
||||
out.writeBoolean(hasExtendedBounds);
|
||||
if (hasExtendedBounds) {
|
||||
extendedBounds.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean usesNewStyleSerialization() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public long interval() {
|
||||
return interval;
|
||||
}
|
||||
|
@ -150,53 +190,10 @@ public abstract class AbstractHistogramBuilder<AB extends AbstractHistogramBuild
|
|||
return InternalHistogram.TYPE.name();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected AB innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in)
|
||||
throws IOException {
|
||||
AbstractHistogramBuilder<AB> factory = createFactoryFromStream(name, in);
|
||||
factory.interval = in.readVLong();
|
||||
factory.offset = in.readLong();
|
||||
if (in.readBoolean()) {
|
||||
factory.order = InternalOrder.Streams.readOrder(in);
|
||||
}
|
||||
factory.keyed = in.readBoolean();
|
||||
factory.minDocCount = in.readVLong();
|
||||
if (in.readBoolean()) {
|
||||
factory.extendedBounds = ExtendedBounds.readFrom(in);
|
||||
}
|
||||
return (AB) factory;
|
||||
}
|
||||
|
||||
protected abstract AB createFactoryFromStream(String name, StreamInput in) throws IOException;
|
||||
|
||||
@Override
|
||||
protected void innerWriteTo(StreamOutput out) throws IOException {
|
||||
writeFactoryToStream(out);
|
||||
out.writeVLong(interval);
|
||||
out.writeLong(offset);
|
||||
boolean hasOrder = order != null;
|
||||
out.writeBoolean(hasOrder);
|
||||
if (hasOrder) {
|
||||
InternalOrder.Streams.writeOrder(order, out);
|
||||
}
|
||||
out.writeBoolean(keyed);
|
||||
out.writeVLong(minDocCount);
|
||||
boolean hasExtendedBounds = extendedBounds != null;
|
||||
out.writeBoolean(hasExtendedBounds);
|
||||
if (hasExtendedBounds) {
|
||||
extendedBounds.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeFactoryToStream(StreamOutput out) throws IOException {
|
||||
// Default impl does nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int innerHashCode() {
|
||||
return Objects.hash(interval, offset, order, keyed, minDocCount, extendedBounds);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean innerEquals(Object obj) {
|
||||
|
|
|
@ -19,22 +19,24 @@
|
|||
|
||||
package org.elasticsearch.search.aggregations.bucket.histogram;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
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.support.AggregationContext;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DateHistogramAggregatorBuilder extends AbstractHistogramBuilder<DateHistogramAggregatorBuilder> {
|
||||
|
||||
public static final DateHistogramAggregatorBuilder PROTOTYPE = new DateHistogramAggregatorBuilder("");
|
||||
public static final String NAME = InternalDateHistogram.TYPE.name();
|
||||
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
private DateHistogramInterval dateHistogramInterval;
|
||||
|
||||
|
@ -42,6 +44,26 @@ public class DateHistogramAggregatorBuilder extends AbstractHistogramBuilder<Dat
|
|||
super(name, InternalDateHistogram.HISTOGRAM_FACTORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public DateHistogramAggregatorBuilder(StreamInput in) throws IOException {
|
||||
super(in, InternalDateHistogram.HISTOGRAM_FACTORY);
|
||||
if (in.readBoolean()) {
|
||||
dateHistogramInterval = DateHistogramInterval.readFromStream(in);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerWriteTo(StreamOutput out) throws IOException {
|
||||
super.innerWriteTo(out);
|
||||
boolean hasDateInterval = dateHistogramInterval != null;
|
||||
out.writeBoolean(hasDateInterval);
|
||||
if (hasDateInterval) {
|
||||
dateHistogramInterval.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the interval.
|
||||
*/
|
||||
|
@ -85,7 +107,7 @@ public class DateHistogramAggregatorBuilder extends AbstractHistogramBuilder<Dat
|
|||
|
||||
@Override
|
||||
public String getWriteableName() {
|
||||
return InternalDateHistogram.TYPE.name();
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,24 +120,6 @@ public class DateHistogramAggregatorBuilder extends AbstractHistogramBuilder<Dat
|
|||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DateHistogramAggregatorBuilder createFactoryFromStream(String name, StreamInput in) throws IOException {
|
||||
DateHistogramAggregatorBuilder factory = new DateHistogramAggregatorBuilder(name);
|
||||
if (in.readBoolean()) {
|
||||
factory.dateHistogramInterval = DateHistogramInterval.readFromStream(in);
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeFactoryToStream(StreamOutput out) throws IOException {
|
||||
boolean hasDateInterval = dateHistogramInterval != null;
|
||||
out.writeBoolean(hasDateInterval);
|
||||
if (hasDateInterval) {
|
||||
dateHistogramInterval.writeTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int innerHashCode() {
|
||||
return Objects.hash(super.innerHashCode(), dateHistogramInterval);
|
||||
|
|
|
@ -36,11 +36,6 @@ public class DateHistogramParser extends HistogramParser {
|
|||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return InternalDateHistogram.TYPE.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object parseStringInterval(String text) {
|
||||
return new DateHistogramInterval(text);
|
||||
|
@ -96,9 +91,4 @@ public class DateHistogramParser extends HistogramParser {
|
|||
protected long parseStringOffset(String offset) throws IOException {
|
||||
return DateHistogramAggregatorBuilder.parseStringOffset(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DateHistogramAggregatorBuilder getFactoryPrototypes() {
|
||||
return DateHistogramAggregatorBuilder.PROTOTYPE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,25 +19,29 @@
|
|||
|
||||
package org.elasticsearch.search.aggregations.bucket.histogram;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
|
||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.support.AggregationContext;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
|
||||
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HistogramAggregatorBuilder extends AbstractHistogramBuilder<HistogramAggregatorBuilder> {
|
||||
public static final HistogramAggregatorBuilder PROTOTYPE = new HistogramAggregatorBuilder("");
|
||||
public static final String NAME = InternalHistogram.TYPE.name();
|
||||
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
|
||||
|
||||
public HistogramAggregatorBuilder(String name) {
|
||||
super(name, InternalHistogram.HISTOGRAM_FACTORY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HistogramAggregatorBuilder createFactoryFromStream(String name, StreamInput in) throws IOException {
|
||||
return new HistogramAggregatorBuilder(name);
|
||||
/**
|
||||
* Read from a stream.
|
||||
*/
|
||||
public HistogramAggregatorBuilder(StreamInput in) throws IOException {
|
||||
super(in, InternalHistogram.HISTOGRAM_FACTORY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -44,11 +44,6 @@ public class HistogramParser extends NumericValuesSourceParser {
|
|||
super(true, true, timezoneAware);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
return InternalHistogram.TYPE.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractHistogramBuilder<?> createFactory(String aggregationName, ValuesSourceType valuesSourceType,
|
||||
ValueType targetValueType, Map<ParseField, Object> otherOptions) {
|
||||
|
@ -160,9 +155,4 @@ public class HistogramParser extends NumericValuesSourceParser {
|
|||
}
|
||||
return new InternalOrder.Aggregation(key, asc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractHistogramBuilder<?> getFactoryPrototypes() {
|
||||
return HistogramAggregatorBuilder.PROTOTYPE;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue