diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValue.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValue.java index 0f8eec4e66a..a3c7012f7cd 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValue.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValue.java @@ -25,15 +25,15 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation; -import org.elasticsearch.search.aggregations.metrics.max.InternalMax; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Objects; public class InternalSimpleValue extends InternalNumericMetricsAggregation.SingleValue implements SimpleValue { public static final String NAME = "simple_value"; - private final double value; + protected final double value; public InternalSimpleValue(String name, double value, DocValueFormat formatter, List pipelineAggregators, Map metaData) { @@ -72,7 +72,7 @@ public class InternalSimpleValue extends InternalNumericMetricsAggregation.Singl } @Override - public InternalMax doReduce(List aggregations, ReduceContext reduceContext) { + public InternalSimpleValue doReduce(List aggregations, ReduceContext reduceContext) { throw new UnsupportedOperationException("Not supported"); } @@ -85,4 +85,15 @@ public class InternalSimpleValue extends InternalNumericMetricsAggregation.Singl } return builder; } + + @Override + protected int doHashCode() { + return Objects.hash(value); + } + + @Override + protected boolean doEquals(Object obj) { + InternalSimpleValue other = (InternalSimpleValue) obj; + return Objects.equals(value, other.value); + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivative.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivative.java index e18c0d81eeb..db56f0f7c6f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivative.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivative.java @@ -29,6 +29,7 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Objects; public class InternalDerivative extends InternalSimpleValue implements Derivative { private final double normalizationFactor; @@ -89,4 +90,16 @@ public class InternalDerivative extends InternalSimpleValue implements Derivativ } return builder; } + + @Override + protected int doHashCode() { + return Objects.hash(normalizationFactor, value); + } + + @Override + protected boolean doEquals(Object obj) { + InternalDerivative other = (InternalDerivative) obj; + return Objects.equals(value, other.value) + && Objects.equals(normalizationFactor, other.normalizationFactor); + } } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java index f5a06e09fd3..05d75d9af77 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java @@ -50,7 +50,7 @@ public abstract class InternalAggregationTestCase return createTestInstance(name, pipelineAggregators, metaData); } - public final void testReduceRandom() { + public void testReduceRandom() { String name = randomAsciiOfLength(5); List inputs = new ArrayList<>(); List toReduce = new ArrayList<>(); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java new file mode 100644 index 00000000000..afb5d869d0e --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/InternalSimpleValueTests.java @@ -0,0 +1,58 @@ +/* + * 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; + +import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.search.DocValueFormat; +import org.elasticsearch.search.aggregations.InternalAggregationTestCase; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class InternalSimpleValueTests extends InternalAggregationTestCase{ + + @Override + protected InternalSimpleValue createTestInstance(String name, + List pipelineAggregators, Map metaData) { + DocValueFormat formatter = randomFrom(DocValueFormat.BOOLEAN, DocValueFormat.GEOHASH, + DocValueFormat.IP, DocValueFormat.RAW); + double value = randomDoubleBetween(0, 100000, true); + return new InternalSimpleValue(name, value, formatter, pipelineAggregators, metaData); + } + + @Override + public void testReduceRandom() { + expectThrows(UnsupportedOperationException.class, + () -> createTestInstance("name", Collections.emptyList(), null).reduce(null, + null)); + } + + @Override + protected void assertReduced(InternalSimpleValue reduced, List inputs) { + // no test since reduce operation is unsupported + } + + @Override + protected Reader instanceReader() { + return InternalSimpleValue::new; + } + +} diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivativeTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivativeTests.java new file mode 100644 index 00000000000..1889723fa8a --- /dev/null +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/derivative/InternalDerivativeTests.java @@ -0,0 +1,61 @@ +/* + * 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.derivative; + +import org.elasticsearch.common.io.stream.Writeable.Reader; +import org.elasticsearch.search.DocValueFormat; +import org.elasticsearch.search.aggregations.InternalAggregationTestCase; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +public class InternalDerivativeTests extends InternalAggregationTestCase { + + @Override + protected InternalDerivative createTestInstance(String name, + List pipelineAggregators, Map metaData) { + DocValueFormat formatter = randomFrom(DocValueFormat.BOOLEAN, DocValueFormat.GEOHASH, + DocValueFormat.IP, DocValueFormat.RAW); + double value = randomDoubleBetween(0, 100000, true); + double normalizationFactor = randomDoubleBetween(0, 100000, true); + return new InternalDerivative(name, value, normalizationFactor, formatter, + pipelineAggregators, metaData); + } + + @Override + public void testReduceRandom() { + expectThrows(UnsupportedOperationException.class, + () -> createTestInstance("name", Collections.emptyList(), null).reduce(null, + null)); + } + + @Override + protected void assertReduced(InternalDerivative reduced, List inputs) { + // no test since reduce operation is unsupported + } + + @Override + protected Reader instanceReader() { + return InternalDerivative::new; + } + +}