Aggregations Refactor: Refactor Avg Bucket, Min Bucket, Max Bucket, Sum Bucket, Percentiles Bucket, Stats Bucket and Extended Stats Bucket Aggregations

This commit is contained in:
Colin Goodheart-Smithe 2015-11-25 11:40:35 +00:00
parent 75f20c494d
commit a0e60bf228
24 changed files with 747 additions and 124 deletions

View File

@ -0,0 +1,144 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
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.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.support.format.ValueFormat;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public abstract class BucketMetricsFactory extends PipelineAggregatorFactory {
private String format = null;
private GapPolicy gapPolicy = GapPolicy.SKIP;
public BucketMetricsFactory(String name, String type, String[] bucketsPaths) {
super(name, type, bucketsPaths);
}
/**
* Sets the format to use on the output of this aggregation.
*/
public void format(String format) {
this.format = format;
}
/**
* Gets the format to use on the output of this aggregation.
*/
public String format() {
return format;
}
protected ValueFormatter formatter() {
if (format != null) {
return ValueFormat.Patternable.Number.format(format).formatter();
} else {
return ValueFormatter.RAW;
}
}
/**
* Sets the gap policy to use for this aggregation.
*/
public void gapPolicy(GapPolicy gapPolicy) {
this.gapPolicy = gapPolicy;
}
/**
* Gets the gap policy to use for this aggregation.
*/
public GapPolicy gapPolicy() {
return gapPolicy;
}
@Override
protected abstract PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException;
@Override
public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories,
List<PipelineAggregatorFactory> pipelineAggregatorFactories) {
if (bucketsPaths.length != 1) {
throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName()
+ " must contain a single entry for aggregation [" + name + "]");
}
}
@Override
protected final XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
if (format != null) {
builder.field(BucketMetricsParser.FORMAT.getPreferredName(), format);
}
if (gapPolicy != null) {
builder.field(BucketMetricsParser.GAP_POLICY.getPreferredName(), gapPolicy.getName());
}
doXContentBody(builder, params);
return builder;
}
protected abstract XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException;
@Override
protected final PipelineAggregatorFactory doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
BucketMetricsFactory factory = innerReadFrom(name, bucketsPaths, in);
factory.format = in.readOptionalString();
factory.gapPolicy = GapPolicy.readFrom(in);
return factory;
}
protected abstract BucketMetricsFactory innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException;
@Override
protected final void doWriteTo(StreamOutput out) throws IOException {
innerWriteTo(out);
out.writeOptionalString(format);
gapPolicy.writeTo(out);
}
protected abstract void innerWriteTo(StreamOutput out) throws IOException;
@Override
protected final int doHashCode() {
return Objects.hash(format, gapPolicy, innerHashCode());
}
protected abstract int innerHashCode();
@Override
protected final boolean doEquals(Object obj) {
BucketMetricsFactory other = (BucketMetricsFactory) obj;
return Objects.equals(format, other.format)
&& Objects.equals(gapPolicy, other.gapPolicy)
&& innerEquals(other);
}
protected abstract boolean innerEquals(BucketMetricsFactory other);
}

View File

@ -25,8 +25,6 @@ import org.elasticsearch.search.SearchParseException;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.support.format.ValueFormat;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SearchContext;
import java.io.IOException; import java.io.IOException;
@ -53,7 +51,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser {
String currentFieldName = null; String currentFieldName = null;
String[] bucketsPaths = null; String[] bucketsPaths = null;
String format = null; String format = null;
GapPolicy gapPolicy = GapPolicy.SKIP; GapPolicy gapPolicy = null;
Map<String, Object> leftover = new HashMap<>(5); Map<String, Object> leftover = new HashMap<>(5);
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
@ -90,16 +88,15 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser {
+ "] for aggregation [" + pipelineAggregatorName + "]", parser.getTokenLocation()); + "] for aggregation [" + pipelineAggregatorName + "]", parser.getTokenLocation());
} }
ValueFormatter formatter = null; BucketMetricsFactory factory = null;
if (format != null) {
formatter = ValueFormat.Patternable.Number.format(format).formatter();
} else {
formatter = ValueFormatter.RAW;
}
PipelineAggregatorFactory factory = null;
try { try {
factory = buildFactory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter, leftover); factory = buildFactory(pipelineAggregatorName, bucketsPaths, leftover);
if (format != null) {
factory.format(format);
}
if (gapPolicy != null) {
factory.gapPolicy(gapPolicy);
}
} catch (ParseException exception) { } catch (ParseException exception) {
throw new SearchParseException(context, "Could not parse settings for aggregation [" throw new SearchParseException(context, "Could not parse settings for aggregation ["
+ pipelineAggregatorName + "].", null, exception); + pipelineAggregatorName + "].", null, exception);
@ -113,7 +110,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser {
return factory; return factory;
} }
protected abstract PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, protected abstract BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths,
ValueFormatter formatter, Map<String, Object> unparsedParams) throws ParseException; Map<String, Object> unparsedParams) throws ParseException;
} }

View File

@ -19,10 +19,9 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.util.Map; import java.util.Map;
@ -33,14 +32,11 @@ public class AvgBucketParser extends BucketMetricsParser {
} }
@Override @Override
protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map<String, Object> unparsedParams) {
ValueFormatter formatter, Map<String, Object> unparsedParams) { return new AvgBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths);
return new AvgBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter);
} }
// NORELEASE implement this method when refactoring this aggregation
@Override @Override
public PipelineAggregatorFactory getFactoryPrototype() { public PipelineAggregatorFactory getFactoryPrototype() {
return null; return new AvgBucketPipelineAggregator.Factory(null, null);
} }
} }

View File

@ -20,6 +20,8 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg;
import org.elasticsearch.common.io.stream.StreamInput; 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.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregation.Type;
@ -28,6 +30,7 @@ import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -86,20 +89,15 @@ public class AvgBucketPipelineAggregator extends BucketMetricsPipelineAggregator
return new InternalSimpleValue(name(), avgValue, formatter, pipelineAggregators, metadata); return new InternalSimpleValue(name(), avgValue, formatter, pipelineAggregators, metadata);
} }
public static class Factory extends PipelineAggregatorFactory { public static class Factory extends BucketMetricsFactory {
private final ValueFormatter formatter; public Factory(String name, String[] bucketsPaths) {
private final GapPolicy gapPolicy;
public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) {
super(name, TYPE.name(), bucketsPaths); super(name, TYPE.name(), bucketsPaths);
this.gapPolicy = gapPolicy;
this.formatter = formatter;
} }
@Override @Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException { protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
return new AvgBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); return new AvgBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }
@Override @Override
@ -110,6 +108,31 @@ public class AvgBucketPipelineAggregator extends BucketMetricsPipelineAggregator
} }
} }
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
return builder;
}
@Override
protected BucketMetricsFactory innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
return new Factory(name, bucketsPaths);
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
// Do nothing, no extra state to write to stream
}
@Override
protected int innerHashCode() {
return 0;
}
@Override
protected boolean innerEquals(BucketMetricsFactory other) {
return true;
}
} }
} }

View File

@ -19,10 +19,9 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.util.Map; import java.util.Map;
@ -34,15 +33,13 @@ public class MaxBucketParser extends BucketMetricsParser {
} }
@Override @Override
protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map<String, Object> unparsedParams) {
ValueFormatter formatter, Map<String, Object> unparsedParams) { return new MaxBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths);
return new MaxBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter);
} }
// NORELEASE implement this method when refactoring this aggregation
@Override @Override
public PipelineAggregatorFactory getFactoryPrototype() { public PipelineAggregatorFactory getFactoryPrototype() {
return null; return new MaxBucketPipelineAggregator.Factory(null, null);
} }
} }

View File

@ -20,6 +20,8 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max;
import org.elasticsearch.common.io.stream.StreamInput; 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.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregation.Type;
@ -27,6 +29,7 @@ import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -93,20 +96,15 @@ public class MaxBucketPipelineAggregator extends BucketMetricsPipelineAggregator
return new InternalBucketMetricValue(name(), keys, maxValue, formatter, Collections.emptyList(), metaData()); return new InternalBucketMetricValue(name(), keys, maxValue, formatter, Collections.emptyList(), metaData());
} }
public static class Factory extends PipelineAggregatorFactory { public static class Factory extends BucketMetricsFactory {
private final ValueFormatter formatter; public Factory(String name, String[] bucketsPaths) {
private final GapPolicy gapPolicy;
public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) {
super(name, TYPE.name(), bucketsPaths); super(name, TYPE.name(), bucketsPaths);
this.gapPolicy = gapPolicy;
this.formatter = formatter;
} }
@Override @Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException { protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
return new MaxBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); return new MaxBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }
@Override @Override
@ -118,6 +116,31 @@ public class MaxBucketPipelineAggregator extends BucketMetricsPipelineAggregator
} }
} }
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
return builder;
}
@Override
protected BucketMetricsFactory innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
return new Factory(name, bucketsPaths);
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
// Do nothing, no extra state to write to stream
}
@Override
protected int innerHashCode() {
return 0;
}
@Override
protected boolean innerEquals(BucketMetricsFactory other) {
return true;
}
} }
} }

View File

@ -19,10 +19,9 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.util.Map; import java.util.Map;
@ -34,15 +33,13 @@ public class MinBucketParser extends BucketMetricsParser {
} }
@Override @Override
protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map<String, Object> unparsedParams) {
ValueFormatter formatter, Map<String, Object> unparsedParams) { return new MinBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths);
return new MinBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter);
} }
// NORELEASE implement this method when refactoring this aggregation
@Override @Override
public PipelineAggregatorFactory getFactoryPrototype() { public PipelineAggregatorFactory getFactoryPrototype() {
return null; return new MinBucketPipelineAggregator.Factory(null, null);
} }
} }

View File

@ -20,6 +20,8 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min;
import org.elasticsearch.common.io.stream.StreamInput; 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.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregation.Type;
@ -27,6 +29,7 @@ import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -94,20 +97,15 @@ public class MinBucketPipelineAggregator extends BucketMetricsPipelineAggregator
return new InternalBucketMetricValue(name(), keys, minValue, formatter, Collections.emptyList(), metaData()); return new InternalBucketMetricValue(name(), keys, minValue, formatter, Collections.emptyList(), metaData());
}; };
public static class Factory extends PipelineAggregatorFactory { public static class Factory extends BucketMetricsFactory {
private final ValueFormatter formatter; public Factory(String name, String[] bucketsPaths) {
private final GapPolicy gapPolicy;
public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) {
super(name, TYPE.name(), bucketsPaths); super(name, TYPE.name(), bucketsPaths);
this.gapPolicy = gapPolicy;
this.formatter = formatter;
} }
@Override @Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException { protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
return new MinBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); return new MinBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }
@Override @Override
@ -119,6 +117,31 @@ public class MinBucketPipelineAggregator extends BucketMetricsPipelineAggregator
} }
} }
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
return builder;
}
@Override
protected BucketMetricsFactory innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
return new Factory(name, bucketsPaths);
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
// Do nothing, no extra state to write to stream
}
@Override
protected int innerHashCode() {
return 0;
}
@Override
protected boolean innerEquals(BucketMetricsFactory other) {
return true;
}
} }
} }

View File

@ -20,10 +20,9 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.text.ParseException; import java.text.ParseException;
import java.util.List; import java.util.List;
@ -40,10 +39,10 @@ public class PercentilesBucketParser extends BucketMetricsParser {
} }
@Override @Override
protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map<String, Object> unparsedParams)
ValueFormatter formatter, Map<String, Object> unparsedParams) throws ParseException { throws ParseException {
double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 }; double[] percents = null;
int counter = 0; int counter = 0;
Object percentParam = unparsedParams.get(PERCENTS.getPreferredName()); Object percentParam = unparsedParams.get(PERCENTS.getPreferredName());
@ -66,12 +65,16 @@ public class PercentilesBucketParser extends BucketMetricsParser {
} }
} }
return new PercentilesBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter, percents); PercentilesBucketPipelineAggregator.Factory factory = new PercentilesBucketPipelineAggregator.Factory(pipelineAggregatorName,
bucketsPaths);
if (percents != null) {
factory.percents(percents);
}
return factory;
} }
// NORELEASE implement this method when refactoring this aggregation
@Override @Override
public PipelineAggregatorFactory getFactoryPrototype() { public PipelineAggregatorFactory getFactoryPrototype() {
return null; return new PercentilesBucketPipelineAggregator.Factory(null, null);
} }
} }

View File

@ -19,28 +19,33 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregation.Type;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import static org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAggregator { public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAggregator {
public final static Type TYPE = new Type("percentiles_bucket"); public final static Type TYPE = new Type("percentiles_bucket");
public final ParseField PERCENTS_FIELD = new ParseField("percents");
public final static PipelineAggregatorStreams.Stream STREAM = new PipelineAggregatorStreams.Stream() { public final static PipelineAggregatorStreams.Stream STREAM = new PipelineAggregatorStreams.Stream() {
@Override @Override
@ -119,22 +124,31 @@ public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAg
out.writeDoubleArray(percents); out.writeDoubleArray(percents);
} }
public static class Factory extends PipelineAggregatorFactory { public static class Factory extends BucketMetricsFactory {
private final ValueFormatter formatter; private double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 };
private final GapPolicy gapPolicy;
private final double[] percents;
public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter, double[] percents) { public Factory(String name, String[] bucketsPaths) {
super(name, TYPE.name(), bucketsPaths); super(name, TYPE.name(), bucketsPaths);
this.gapPolicy = gapPolicy; }
this.formatter = formatter;
/**
* Get the percentages to calculate percentiles for in this aggregation
*/
public double[] percents() {
return percents;
}
/**
* Set the percentages to calculate percentiles for in this aggregation
*/
public void percents(double[] percents) {
this.percents = percents; this.percents = percents;
} }
@Override @Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException { protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
return new PercentilesBucketPipelineAggregator(name, percents, bucketsPaths, gapPolicy, formatter, metaData); return new PercentilesBucketPipelineAggregator(name, percents, bucketsPaths, gapPolicy(), formatter(), metaData);
} }
@Override @Override
@ -153,6 +167,37 @@ public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAg
} }
} }
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
if (percents != null) {
builder.field(PercentilesBucketParser.PERCENTS.getPreferredName(), percents);
}
return builder;
}
@Override
protected BucketMetricsFactory innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
Factory factory = new Factory(name, bucketsPaths);
factory.percents = in.readDoubleArray();
return factory;
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
out.writeDoubleArray(percents);
}
@Override
protected int innerHashCode() {
return Arrays.hashCode(percents);
}
@Override
protected boolean innerEquals(BucketMetricsFactory obj) {
Factory other = (Factory) obj;
return Objects.deepEquals(percents, other.percents);
}
} }
} }

View File

@ -19,10 +19,9 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.util.Map; import java.util.Map;
@ -33,14 +32,12 @@ public class StatsBucketParser extends BucketMetricsParser {
} }
@Override @Override
protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map<String, Object> unparsedParams) {
ValueFormatter formatter, Map<String, Object> unparsedParams) { return new StatsBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths);
return new StatsBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter);
} }
// NORELEASE implement this method when refactoring this aggregation
@Override @Override
public PipelineAggregatorFactory getFactoryPrototype() { public PipelineAggregatorFactory getFactoryPrototype() {
return null; return new StatsBucketPipelineAggregator.Factory(null, null);
} }
} }

View File

@ -20,6 +20,8 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats;
import org.elasticsearch.common.io.stream.StreamInput; 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.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregation.Type;
@ -27,6 +29,7 @@ import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -92,20 +95,15 @@ public class StatsBucketPipelineAggregator extends BucketMetricsPipelineAggregat
return new InternalStatsBucket(name(), count, sum, min, max, formatter, pipelineAggregators, metadata); return new InternalStatsBucket(name(), count, sum, min, max, formatter, pipelineAggregators, metadata);
} }
public static class Factory extends PipelineAggregatorFactory { public static class Factory extends BucketMetricsFactory {
private final ValueFormatter formatter; public Factory(String name, String[] bucketsPaths) {
private final GapPolicy gapPolicy;
public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) {
super(name, TYPE.name(), bucketsPaths); super(name, TYPE.name(), bucketsPaths);
this.gapPolicy = gapPolicy;
this.formatter = formatter;
} }
@Override @Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException { protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
return new StatsBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); return new StatsBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }
@Override @Override
@ -117,6 +115,31 @@ public class StatsBucketPipelineAggregator extends BucketMetricsPipelineAggregat
} }
} }
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
return builder;
}
@Override
protected BucketMetricsFactory innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
return new Factory(name, bucketsPaths);
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
// Do nothing, no extra state to write to stream
}
@Override
protected int innerHashCode() {
return 0;
}
@Override
protected boolean innerEquals(BucketMetricsFactory other) {
return true;
}
} }
} }

View File

@ -20,10 +20,9 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.text.ParseException; import java.text.ParseException;
import java.util.Map; import java.util.Map;
@ -37,10 +36,10 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser {
} }
@Override @Override
protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map<String, Object> unparsedParams)
ValueFormatter formatter, Map<String, Object> unparsedParams) throws ParseException { throws ParseException {
double sigma = 2.0; Double sigma = null;
Object param = unparsedParams.get(SIGMA.getPreferredName()); Object param = unparsedParams.get(SIGMA.getPreferredName());
if (param != null) { if (param != null) {
@ -52,12 +51,16 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser {
+ param.getClass().getSimpleName() + "` provided instead", 0); + param.getClass().getSimpleName() + "` provided instead", 0);
} }
} }
return new ExtendedStatsBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, sigma, gapPolicy, formatter); ExtendedStatsBucketPipelineAggregator.Factory factory = new ExtendedStatsBucketPipelineAggregator.Factory(pipelineAggregatorName,
bucketsPaths);
if (sigma != null) {
factory.sigma(sigma);
}
return factory;
} }
// NORELEASE implement this method when refactoring this aggregation
@Override @Override
public PipelineAggregatorFactory getFactoryPrototype() { public PipelineAggregatorFactory getFactoryPrototype() {
return null; return new ExtendedStatsBucketPipelineAggregator.Factory(null, null);
} }
} }

View File

@ -20,6 +20,8 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended;
import org.elasticsearch.common.io.stream.StreamInput; 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.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregation.Type;
@ -27,12 +29,14 @@ import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class ExtendedStatsBucketPipelineAggregator extends BucketMetricsPipelineAggregator { public class ExtendedStatsBucketPipelineAggregator extends BucketMetricsPipelineAggregator {
@ -97,22 +101,33 @@ public class ExtendedStatsBucketPipelineAggregator extends BucketMetricsPipeline
return new InternalExtendedStatsBucket(name(), count, sum, min, max, sumOfSqrs, sigma, formatter, pipelineAggregators, metadata); return new InternalExtendedStatsBucket(name(), count, sum, min, max, sumOfSqrs, sigma, formatter, pipelineAggregators, metadata);
} }
public static class Factory extends PipelineAggregatorFactory { public static class Factory extends BucketMetricsFactory {
private final ValueFormatter formatter; private double sigma = 2.0;
private final GapPolicy gapPolicy;
private final double sigma;
public Factory(String name, String[] bucketsPaths, double sigma, GapPolicy gapPolicy, ValueFormatter formatter) { public Factory(String name, String[] bucketsPaths) {
super(name, TYPE.name(), bucketsPaths); super(name, TYPE.name(), bucketsPaths);
this.gapPolicy = gapPolicy; }
this.formatter = formatter;
/**
* Set the value of sigma to use when calculating the standard deviation
* bounds
*/
public void sigma(double sigma) {
this.sigma = sigma; this.sigma = sigma;
} }
/**
* Get the value of sigma to use when calculating the standard deviation
* bounds
*/
public double sigma() {
return sigma;
}
@Override @Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException { protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
return new ExtendedStatsBucketPipelineAggregator(name, bucketsPaths, sigma, gapPolicy, formatter, metaData); return new ExtendedStatsBucketPipelineAggregator(name, bucketsPaths, sigma, gapPolicy(), formatter(), metaData);
} }
@Override @Override
@ -129,6 +144,35 @@ public class ExtendedStatsBucketPipelineAggregator extends BucketMetricsPipeline
} }
} }
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
builder.field(ExtendedStatsBucketParser.SIGMA.getPreferredName(), sigma);
return builder;
}
@Override
protected BucketMetricsFactory innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
Factory factory = new Factory(name, bucketsPaths);
factory.sigma = in.readDouble();
return factory;
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
out.writeDouble(sigma);
}
@Override
protected int innerHashCode() {
return Objects.hash(sigma);
}
@Override
protected boolean innerEquals(BucketMetricsFactory obj) {
Factory other = (Factory) obj;
return Objects.equals(sigma, other.sigma);
}
} }
} }

View File

@ -19,10 +19,9 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
import java.util.Map; import java.util.Map;
@ -33,14 +32,12 @@ public class SumBucketParser extends BucketMetricsParser {
} }
@Override @Override
protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map<String, Object> unparsedParams) {
ValueFormatter formatter, Map<String, Object> unparsedParams) { return new SumBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths);
return new SumBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter);
} }
// NORELEASE implement this method when refactoring this aggregation
@Override @Override
public PipelineAggregatorFactory getFactoryPrototype() { public PipelineAggregatorFactory getFactoryPrototype() {
return null; return new SumBucketPipelineAggregator.Factory(null, null);
} }
} }

View File

@ -20,6 +20,8 @@
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum; package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum;
import org.elasticsearch.common.io.stream.StreamInput; 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.AggregatorFactory;
import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.InternalAggregation.Type;
@ -28,6 +30,7 @@ import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorFactory;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsFactory;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator;
import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import org.elasticsearch.search.aggregations.support.format.ValueFormatter;
@ -82,20 +85,15 @@ public class SumBucketPipelineAggregator extends BucketMetricsPipelineAggregator
return new InternalSimpleValue(name(), sum, formatter, pipelineAggregators, metadata); return new InternalSimpleValue(name(), sum, formatter, pipelineAggregators, metadata);
} }
public static class Factory extends PipelineAggregatorFactory { public static class Factory extends BucketMetricsFactory {
private final ValueFormatter formatter; public Factory(String name, String[] bucketsPaths) {
private final GapPolicy gapPolicy;
public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) {
super(name, TYPE.name(), bucketsPaths); super(name, TYPE.name(), bucketsPaths);
this.gapPolicy = gapPolicy;
this.formatter = formatter;
} }
@Override @Override
protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException { protected PipelineAggregator createInternal(Map<String, Object> metaData) throws IOException {
return new SumBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); return new SumBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData);
} }
@Override @Override
@ -107,6 +105,31 @@ public class SumBucketPipelineAggregator extends BucketMetricsPipelineAggregator
} }
} }
@Override
protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
return builder;
}
@Override
protected BucketMetricsFactory innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
return new Factory(name, bucketsPaths);
}
@Override
protected void innerWriteTo(StreamOutput out) throws IOException {
// Do nothing, no extra state to write to stream
}
@Override
protected int innerHashCode() {
return 0;
}
@Override
protected boolean innerEquals(BucketMetricsFactory other) {
return true;
}
} }
} }

View File

@ -0,0 +1,44 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
import org.elasticsearch.search.aggregations.BasePipelineAggregationTestCase;
import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
public abstract class AbstractBucketMetricsTestCase<PAF extends BucketMetricsFactory> extends BasePipelineAggregationTestCase<PAF> {
@Override
protected final PAF createTestAggregatorFactory() {
String name = randomAsciiOfLengthBetween(3, 20);
String[] bucketsPaths = new String[1];
bucketsPaths[0] = randomAsciiOfLengthBetween(3, 20);
PAF factory = doCreateTestAggregatorFactory(name, bucketsPaths);
if (randomBoolean()) {
factory.format(randomAsciiOfLengthBetween(1, 10));
}
if (randomBoolean()) {
factory.gapPolicy(randomFrom(GapPolicy.values()));
}
return factory;
}
protected abstract PAF doCreateTestAggregatorFactory(String name, String[] bucketsPaths);
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator.Factory;
public class AvgBucketTests extends AbstractBucketMetricsTestCase<AvgBucketPipelineAggregator.Factory> {
@Override
protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) {
return new Factory(name, bucketsPaths);
}
}

View File

@ -0,0 +1,37 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator.Factory;
public class ExtendedStatsBucketTests extends AbstractBucketMetricsTestCase<ExtendedStatsBucketPipelineAggregator.Factory> {
@Override
protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) {
Factory factory = new Factory(name, bucketsPaths);
if (randomBoolean()) {
factory.sigma(randomDoubleBetween(0.0, 10.0, false));
}
return factory;
}
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator.Factory;
public class MaxBucketTests extends AbstractBucketMetricsTestCase<MaxBucketPipelineAggregator.Factory> {
@Override
protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) {
return new Factory(name, bucketsPaths);
}
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator.Factory;
public class MinBucketTests extends AbstractBucketMetricsTestCase<MinBucketPipelineAggregator.Factory> {
@Override
protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) {
return new Factory(name, bucketsPaths);
}
}

View File

@ -0,0 +1,42 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator.Factory;
public class PercentilesBucketTests extends AbstractBucketMetricsTestCase<PercentilesBucketPipelineAggregator.Factory> {
@Override
protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) {
Factory factory = new Factory(name, bucketsPaths);
if (randomBoolean()) {
int numPercents = randomIntBetween(1, 20);
double[] percents = new double[numPercents];
for (int i = 0; i < numPercents; i++) {
percents[i] = randomDoubleBetween(0.0, 100.0, false);
}
factory.percents(percents);
}
return factory;
}
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator.Factory;
public class StatsBucketTests extends AbstractBucketMetricsTestCase<StatsBucketPipelineAggregator.Factory> {
@Override
protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) {
return new Factory(name, bucketsPaths);
}
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.pipeline.bucketmetrics;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator;
import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator.Factory;
public class SumBucketTests extends AbstractBucketMetricsTestCase<SumBucketPipelineAggregator.Factory> {
@Override
protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) {
return new Factory(name, bucketsPaths);
}
}