diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsFactory.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsFactory.java new file mode 100644 index 00000000000..a74c886cd17 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsFactory.java @@ -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 metaData) throws IOException; + + @Override + public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, + List 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); + +} diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java index 3cf084b239a..d040ccf2f94 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java @@ -25,8 +25,6 @@ import org.elasticsearch.search.SearchParseException; 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 org.elasticsearch.search.internal.SearchContext; import java.io.IOException; @@ -53,7 +51,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser { String currentFieldName = null; String[] bucketsPaths = null; String format = null; - GapPolicy gapPolicy = GapPolicy.SKIP; + GapPolicy gapPolicy = null; Map leftover = new HashMap<>(5); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -90,16 +88,15 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser { + "] for aggregation [" + pipelineAggregatorName + "]", parser.getTokenLocation()); } - ValueFormatter formatter = null; - if (format != null) { - formatter = ValueFormat.Patternable.Number.format(format).formatter(); - } else { - formatter = ValueFormatter.RAW; - } - - PipelineAggregatorFactory factory = null; + BucketMetricsFactory factory = null; 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) { throw new SearchParseException(context, "Could not parse settings for aggregation [" + pipelineAggregatorName + "].", null, exception); @@ -113,7 +110,7 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser { return factory; } - protected abstract PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, - ValueFormatter formatter, Map unparsedParams) throws ParseException; + protected abstract BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, + Map unparsedParams) throws ParseException; } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java index 7db5b0f3790..4589e740072 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java @@ -19,10 +19,9 @@ 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.bucketmetrics.BucketMetricsFactory; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.util.Map; @@ -33,14 +32,11 @@ public class AvgBucketParser extends BucketMetricsParser { } @Override - protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, - ValueFormatter formatter, Map unparsedParams) { - return new AvgBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter); + protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map unparsedParams) { + return new AvgBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths); } - - // NORELEASE implement this method when refactoring this aggregation @Override public PipelineAggregatorFactory getFactoryPrototype() { - return null; + return new AvgBucketPipelineAggregator.Factory(null, null); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregator.java index 3ab134c2e8b..d8c33f8673e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregator.java @@ -20,6 +20,8 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg; 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.InternalAggregation; 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.PipelineAggregatorFactory; 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.support.format.ValueFormatter; @@ -86,20 +89,15 @@ public class AvgBucketPipelineAggregator extends BucketMetricsPipelineAggregator return new InternalSimpleValue(name(), avgValue, formatter, pipelineAggregators, metadata); } - public static class Factory extends PipelineAggregatorFactory { + public static class Factory extends BucketMetricsFactory { - private final ValueFormatter formatter; - private final GapPolicy gapPolicy; - - public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) { + public Factory(String name, String[] bucketsPaths) { super(name, TYPE.name(), bucketsPaths); - this.gapPolicy = gapPolicy; - this.formatter = formatter; } @Override protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new AvgBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); + return new AvgBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); } @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; + } + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java index 59f6e5a1df6..9114ade6882 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java @@ -19,10 +19,9 @@ 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.bucketmetrics.BucketMetricsFactory; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.util.Map; @@ -34,15 +33,13 @@ public class MaxBucketParser extends BucketMetricsParser { } @Override - protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, - ValueFormatter formatter, Map unparsedParams) { - return new MaxBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter); + protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map unparsedParams) { + return new MaxBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths); } - // NORELEASE implement this method when refactoring this aggregation @Override public PipelineAggregatorFactory getFactoryPrototype() { - return null; + return new MaxBucketPipelineAggregator.Factory(null, null); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregator.java index 95a70af7934..2af8c111bee 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregator.java @@ -20,6 +20,8 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max; 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.InternalAggregation; 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.PipelineAggregatorFactory; 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.InternalBucketMetricValue; 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()); } - public static class Factory extends PipelineAggregatorFactory { + public static class Factory extends BucketMetricsFactory { - private final ValueFormatter formatter; - private final GapPolicy gapPolicy; - - public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) { + public Factory(String name, String[] bucketsPaths) { super(name, TYPE.name(), bucketsPaths); - this.gapPolicy = gapPolicy; - this.formatter = formatter; } @Override protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new MaxBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); + return new MaxBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); } @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; + } + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java index 4a9ea9be2ca..474bef7d629 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java @@ -19,10 +19,9 @@ 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.bucketmetrics.BucketMetricsFactory; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.util.Map; @@ -34,15 +33,13 @@ public class MinBucketParser extends BucketMetricsParser { } @Override - protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, - ValueFormatter formatter, Map unparsedParams) { - return new MinBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter); + protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map unparsedParams) { + return new MinBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths); } - // NORELEASE implement this method when refactoring this aggregation @Override public PipelineAggregatorFactory getFactoryPrototype() { - return null; + return new MinBucketPipelineAggregator.Factory(null, null); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregator.java index 755b2060ae6..8f799dcba73 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregator.java @@ -20,6 +20,8 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min; 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.InternalAggregation; 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.PipelineAggregatorFactory; 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.InternalBucketMetricValue; 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()); }; - public static class Factory extends PipelineAggregatorFactory { + public static class Factory extends BucketMetricsFactory { - private final ValueFormatter formatter; - private final GapPolicy gapPolicy; - - public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) { + public Factory(String name, String[] bucketsPaths) { super(name, TYPE.name(), bucketsPaths); - this.gapPolicy = gapPolicy; - this.formatter = formatter; } @Override protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new MinBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); + return new MinBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); } @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; + } + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java index 425e4e3f357..36babbe5f81 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java @@ -20,10 +20,9 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile; 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.bucketmetrics.BucketMetricsFactory; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.text.ParseException; import java.util.List; @@ -40,10 +39,10 @@ public class PercentilesBucketParser extends BucketMetricsParser { } @Override - protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, - ValueFormatter formatter, Map unparsedParams) throws ParseException { + protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map unparsedParams) + 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; 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 public PipelineAggregatorFactory getFactoryPrototype() { - return null; + return new PercentilesBucketPipelineAggregator.Factory(null, null); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregator.java index 24e820481a3..6788b7fa7ed 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregator.java @@ -19,28 +19,33 @@ 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.StreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation; 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.PipelineAggregatorFactory; 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.support.format.ValueFormatter; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; - -import static org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; +import java.util.Objects; public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAggregator { 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() { @Override @@ -119,22 +124,31 @@ public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAg out.writeDoubleArray(percents); } - public static class Factory extends PipelineAggregatorFactory { + public static class Factory extends BucketMetricsFactory { - private final ValueFormatter formatter; - private final GapPolicy gapPolicy; - private final double[] percents; + private double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 }; - public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter, double[] percents) { + public Factory(String name, String[] 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; } @Override protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new PercentilesBucketPipelineAggregator(name, percents, bucketsPaths, gapPolicy, formatter, metaData); + return new PercentilesBucketPipelineAggregator(name, percents, bucketsPaths, gapPolicy(), formatter(), metaData); } @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); + } + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java index 0bb9620ba0e..11830621001 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java @@ -19,10 +19,9 @@ 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.bucketmetrics.BucketMetricsFactory; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.util.Map; @@ -33,14 +32,12 @@ public class StatsBucketParser extends BucketMetricsParser { } @Override - protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, - ValueFormatter formatter, Map unparsedParams) { - return new StatsBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter); + protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map unparsedParams) { + return new StatsBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths); } - // NORELEASE implement this method when refactoring this aggregation @Override public PipelineAggregatorFactory getFactoryPrototype() { - return null; + return new StatsBucketPipelineAggregator.Factory(null, null); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregator.java index 66726cef29e..cc25bc04eb7 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregator.java @@ -20,6 +20,8 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats; 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.InternalAggregation; 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.PipelineAggregatorFactory; 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.support.format.ValueFormatter; @@ -92,20 +95,15 @@ public class StatsBucketPipelineAggregator extends BucketMetricsPipelineAggregat 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; - private final GapPolicy gapPolicy; - - public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) { + public Factory(String name, String[] bucketsPaths) { super(name, TYPE.name(), bucketsPaths); - this.gapPolicy = gapPolicy; - this.formatter = formatter; } @Override protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new StatsBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); + return new StatsBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); } @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; + } + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java index 5fd71ac2f28..2308030a705 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java @@ -20,10 +20,9 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended; 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.bucketmetrics.BucketMetricsFactory; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.text.ParseException; import java.util.Map; @@ -37,10 +36,10 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser { } @Override - protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, - ValueFormatter formatter, Map unparsedParams) throws ParseException { + protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map unparsedParams) + throws ParseException { - double sigma = 2.0; + Double sigma = null; Object param = unparsedParams.get(SIGMA.getPreferredName()); if (param != null) { @@ -52,12 +51,16 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser { + 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 public PipelineAggregatorFactory getFactoryPrototype() { - return null; + return new ExtendedStatsBucketPipelineAggregator.Factory(null, null); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregator.java index 6a7f2bec3f0..647c1be8ed2 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregator.java @@ -20,6 +20,8 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended; 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.InternalAggregation; 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.PipelineAggregatorFactory; 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.support.format.ValueFormatter; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Objects; 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); } - public static class Factory extends PipelineAggregatorFactory { + public static class Factory extends BucketMetricsFactory { - private final ValueFormatter formatter; - private final GapPolicy gapPolicy; - private final double sigma; + private double sigma = 2.0; - public Factory(String name, String[] bucketsPaths, double sigma, GapPolicy gapPolicy, ValueFormatter formatter) { + public Factory(String name, String[] 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; } + /** + * Get the value of sigma to use when calculating the standard deviation + * bounds + */ + public double sigma() { + return sigma; + } + @Override protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new ExtendedStatsBucketPipelineAggregator(name, bucketsPaths, sigma, gapPolicy, formatter, metaData); + return new ExtendedStatsBucketPipelineAggregator(name, bucketsPaths, sigma, gapPolicy(), formatter(), metaData); } @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); + } + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java index f6703edd863..f318c754f02 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java @@ -19,10 +19,9 @@ 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.bucketmetrics.BucketMetricsFactory; import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser; -import org.elasticsearch.search.aggregations.support.format.ValueFormatter; import java.util.Map; @@ -33,14 +32,12 @@ public class SumBucketParser extends BucketMetricsParser { } @Override - protected PipelineAggregatorFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, GapPolicy gapPolicy, - ValueFormatter formatter, Map unparsedParams) { - return new SumBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths, gapPolicy, formatter); + protected BucketMetricsFactory buildFactory(String pipelineAggregatorName, String[] bucketsPaths, Map unparsedParams) { + return new SumBucketPipelineAggregator.Factory(pipelineAggregatorName, bucketsPaths); } - // NORELEASE implement this method when refactoring this aggregation @Override public PipelineAggregatorFactory getFactoryPrototype() { - return null; + return new SumBucketPipelineAggregator.Factory(null, null); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregator.java index 138bd6320c7..2e912e05aed 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregator.java @@ -20,6 +20,8 @@ package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum; 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.InternalAggregation; 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.PipelineAggregatorFactory; 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.support.format.ValueFormatter; @@ -82,20 +85,15 @@ public class SumBucketPipelineAggregator extends BucketMetricsPipelineAggregator return new InternalSimpleValue(name(), sum, formatter, pipelineAggregators, metadata); } - public static class Factory extends PipelineAggregatorFactory { + public static class Factory extends BucketMetricsFactory { - private final ValueFormatter formatter; - private final GapPolicy gapPolicy; - - public Factory(String name, String[] bucketsPaths, GapPolicy gapPolicy, ValueFormatter formatter) { + public Factory(String name, String[] bucketsPaths) { super(name, TYPE.name(), bucketsPaths); - this.gapPolicy = gapPolicy; - this.formatter = formatter; } @Override protected PipelineAggregator createInternal(Map metaData) throws IOException { - return new SumBucketPipelineAggregator(name, bucketsPaths, gapPolicy, formatter, metaData); + return new SumBucketPipelineAggregator(name, bucketsPaths, gapPolicy(), formatter(), metaData); } @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; + } + } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AbstractBucketMetricsTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AbstractBucketMetricsTestCase.java new file mode 100644 index 00000000000..8cfea91c817 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AbstractBucketMetricsTestCase.java @@ -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 extends BasePipelineAggregationTestCase { + + @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); + +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java new file mode 100644 index 00000000000..f49c98db5f8 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/AvgBucketTests.java @@ -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 { + + @Override + protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) { + return new Factory(name, bucketsPaths); + } + + +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java new file mode 100644 index 00000000000..03d7c69a63f --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/ExtendedStatsBucketTests.java @@ -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 { + + @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; + } + + +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MaxBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MaxBucketTests.java new file mode 100644 index 00000000000..74fc39ecad9 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MaxBucketTests.java @@ -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 { + + @Override + protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) { + return new Factory(name, bucketsPaths); + } + + +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java new file mode 100644 index 00000000000..bc8fd2a2597 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/MinBucketTests.java @@ -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 { + + @Override + protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) { + return new Factory(name, bucketsPaths); + } + + +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java new file mode 100644 index 00000000000..60785848d56 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/PercentilesBucketTests.java @@ -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 { + + @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; + } + + +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/StatsBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/StatsBucketTests.java new file mode 100644 index 00000000000..0aa8df0bf9d --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/StatsBucketTests.java @@ -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 { + + @Override + protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) { + return new Factory(name, bucketsPaths); + } + + +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java new file mode 100644 index 00000000000..a7d6b5a9273 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/SumBucketTests.java @@ -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 { + + @Override + protected Factory doCreateTestAggregatorFactory(String name, String[] bucketsPaths) { + return new Factory(name, bucketsPaths); + } + + +}