Skip to content

Commit

Permalink
Remove interface for transport client (#84640)
Browse files Browse the repository at this point in the history
This removes the `Min` interface that was important for the transport
client and renames `InternalMin` to `Min`. The transport client isn't a
thing any more so we don't need to keep these interfaces around any
more.

Related to #82273
  • Loading branch information
nik9000 committed Mar 21, 2022
1 parent 21a5a55 commit dc8ec42
Show file tree
Hide file tree
Showing 30 changed files with 230 additions and 265 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.elasticsearch.search.aggregations.AggregatorTestCase;
import org.elasticsearch.search.aggregations.bucket.terms.LongTerms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.InternalMin;
import org.elasticsearch.search.aggregations.metrics.Min;
import org.elasticsearch.search.aggregations.metrics.MinAggregationBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void testNoDocs() throws IOException {
Aggregation parentAggregation = childrenToParent.getAggregations().get("in_parent");
assertEquals(0, childrenToParent.getDocCount());
assertNotNull("Aggregations: " + childrenToParent.getAggregations().asMap(), parentAggregation);
assertEquals(Double.POSITIVE_INFINITY, ((InternalMin) parentAggregation).getValue(), Double.MIN_VALUE);
assertEquals(Double.POSITIVE_INFINITY, ((Min) parentAggregation).value(), Double.MIN_VALUE);
assertFalse(JoinAggregationInspectionHelper.hasValue(childrenToParent));
});
indexReader.close();
Expand Down Expand Up @@ -105,7 +105,7 @@ public void testParentChild() throws IOException {
expectedTotalParents,
parent.getDocCount()
);
assertEquals(expectedMinValue, ((InternalMin) parent.getAggregations().get("in_parent")).getValue(), Double.MIN_VALUE);
assertEquals(expectedMinValue, ((Min) parent.getAggregations().get("in_parent")).value(), Double.MIN_VALUE);
assertTrue(JoinAggregationInspectionHelper.hasValue(parent));
});

Expand All @@ -119,7 +119,7 @@ public void testParentChild() throws IOException {
);
assertEquals(
expectedParentChildRelations.get(parent).v2(),
((InternalMin) aggregation.getAggregations().get("in_parent")).getValue(),
((Min) aggregation.getAggregations().get("in_parent")).value(),
Double.MIN_VALUE
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.elasticsearch.search.aggregations.AggregatorTestCase;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.InternalMin;
import org.elasticsearch.search.aggregations.metrics.Min;
import org.elasticsearch.search.aggregations.metrics.MinAggregationBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -66,11 +66,7 @@ public void testNoDocs() throws IOException {

testCase(new MatchAllDocsQuery(), newSearcher(indexReader, false, true), parentToChild -> {
assertEquals(0, parentToChild.getDocCount());
assertEquals(
Double.POSITIVE_INFINITY,
((InternalMin) parentToChild.getAggregations().get("in_child")).getValue(),
Double.MIN_VALUE
);
assertEquals(Double.POSITIVE_INFINITY, ((Min) parentToChild.getAggregations().get("in_child")).value(), Double.MIN_VALUE);
});
indexReader.close();
directory.close();
Expand Down Expand Up @@ -99,15 +95,15 @@ public void testParentChild() throws IOException {
}
assertEquals(expectedTotalChildren, child.getDocCount());
assertTrue(JoinAggregationInspectionHelper.hasValue(child));
assertEquals(expectedMinValue, ((InternalMin) child.getAggregations().get("in_child")).getValue(), Double.MIN_VALUE);
assertEquals(expectedMinValue, ((Min) child.getAggregations().get("in_child")).value(), Double.MIN_VALUE);
});

for (String parent : expectedParentChildRelations.keySet()) {
testCase(new TermInSetQuery(IdFieldMapper.NAME, Uid.encodeId(parent)), indexSearcher, child -> {
assertEquals((long) expectedParentChildRelations.get(parent).v1(), child.getDocCount());
assertEquals(
expectedParentChildRelations.get(parent).v2(),
((InternalMin) child.getAggregations().get("in_child")).getValue(),
((Min) child.getAggregations().get("in_child")).value(),
Double.MIN_VALUE
);
});
Expand Down Expand Up @@ -161,16 +157,16 @@ public void testParentChildAsSubAgg() throws IOException {

StringTerms.Bucket evenBucket = result.getBucketByKey("even");
InternalChildren evenChildren = evenBucket.getAggregations().get("children");
InternalMin evenMin = evenChildren.getAggregations().get("min");
Min evenMin = evenChildren.getAggregations().get("min");
assertThat(evenChildren.getDocCount(), equalTo(expectedEvenChildCount));
assertThat(evenMin.getValue(), equalTo(expectedEvenMin));
assertThat(evenMin.value(), equalTo(expectedEvenMin));

if (expectedOddChildCount > 0) {
StringTerms.Bucket oddBucket = result.getBucketByKey("odd");
InternalChildren oddChildren = oddBucket.getAggregations().get("children");
InternalMin oddMin = oddChildren.getAggregations().get("min");
Min oddMin = oddChildren.getAggregations().get("min");
assertThat(oddChildren.getDocCount(), equalTo(expectedOddChildCount));
assertThat(oddMin.getValue(), equalTo(expectedOddMin));
assertThat(oddMin.value(), equalTo(expectedOddMin));
} else {
assertNull(result.getBucketByKey("odd"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentileRanks;
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentiles;
import org.elasticsearch.search.aggregations.metrics.InternalMedianAbsoluteDeviation;
import org.elasticsearch.search.aggregations.metrics.InternalMin;
import org.elasticsearch.search.aggregations.metrics.InternalScriptedMetric;
import org.elasticsearch.search.aggregations.metrics.InternalStats;
import org.elasticsearch.search.aggregations.metrics.InternalTDigestPercentileRanks;
Expand All @@ -180,6 +179,7 @@
import org.elasticsearch.search.aggregations.metrics.Max;
import org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.MedianAbsoluteDeviationAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.Min;
import org.elasticsearch.search.aggregations.metrics.MinAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.PercentileRanksAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.PercentilesAggregationBuilder;
Expand Down Expand Up @@ -371,7 +371,7 @@ private ValuesSourceRegistry registerAggregations(List<SearchPlugin> plugins) {
);
registerAggregation(
new AggregationSpec(MinAggregationBuilder.NAME, MinAggregationBuilder::new, MinAggregationBuilder.PARSER).addResultReader(
InternalMin::new
Min::new
).setAggregatorRegistrar(MinAggregationBuilder::registerAggregators),
builder
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,87 @@
*/
package org.elasticsearch.search.aggregations.metrics;

/**
* An aggregation that computes the minimum of the values in the current bucket.
*/
public interface Min extends NumericMetricsAggregation.SingleValue {
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationReduceContext;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.support.SamplingContext;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class Min extends InternalNumericMetricsAggregation.SingleValue {
private final double min;

public Min(String name, double min, DocValueFormat formatter, Map<String, Object> metadata) {
super(name, formatter, metadata);
this.min = min;
}

/**
* The minimum.
* Read from a stream.
*/
double getValue();
public Min(StreamInput in) throws IOException {
super(in);
min = in.readDouble();
}

@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeNamedWriteable(format);
out.writeDouble(min);
}

@Override
public String getWriteableName() {
return MinAggregationBuilder.NAME;
}

@Override
public double value() {
return min;
}

@Override
public Min reduce(List<InternalAggregation> aggregations, AggregationReduceContext reduceContext) {
double min = Double.POSITIVE_INFINITY;
for (InternalAggregation aggregation : aggregations) {
min = Math.min(min, ((Min) aggregation).min);
}
return new Min(getName(), min, this.format, getMetadata());
}

@Override
public InternalAggregation finalizeSampling(SamplingContext samplingContext) {
return this;
}

@Override
public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
boolean hasValue = Double.isInfinite(min) == false;
builder.field(CommonFields.VALUE.getPreferredName(), hasValue ? min : null);
if (hasValue && format != DocValueFormat.RAW) {
builder.field(CommonFields.VALUE_AS_STRING.getPreferredName(), format.format(min).toString());
}
return builder;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), min);
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
if (super.equals(obj) == false) return false;
Min other = (Min) obj;
return Objects.equals(min, other.min);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public InternalAggregation buildAggregation(long bucket) {
if (valuesSource == null || bucket >= mins.size()) {
return buildEmptyAggregation();
}
return new InternalMin(name, mins.get(bucket), format, metadata());
return new Min(name, mins.get(bucket), format, metadata());
}

@Override
public InternalAggregation buildEmptyAggregation() {
return new InternalMin(name, Double.POSITIVE_INFINITY, format, metadata());
return new Min(name, Double.POSITIVE_INFINITY, format, metadata());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@

import java.io.IOException;

public class ParsedMin extends ParsedSingleValueNumericMetricsAggregation implements Min {

@Override
public double getValue() {
return value();
}

public class ParsedMin extends ParsedSingleValueNumericMetricsAggregation {
@Override
public String getType() {
return MinAggregationBuilder.NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentileRanks;
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentiles;
import org.elasticsearch.search.aggregations.metrics.InternalMedianAbsoluteDeviation;
import org.elasticsearch.search.aggregations.metrics.InternalMin;
import org.elasticsearch.search.aggregations.metrics.InternalScriptedMetric;
import org.elasticsearch.search.aggregations.metrics.InternalStats;
import org.elasticsearch.search.aggregations.metrics.InternalTDigestPercentileRanks;
Expand All @@ -45,6 +44,7 @@
import org.elasticsearch.search.aggregations.metrics.InternalWeightedAvg;
import org.elasticsearch.search.aggregations.metrics.Max;
import org.elasticsearch.search.aggregations.metrics.MetricInspectionHelper;
import org.elasticsearch.search.aggregations.metrics.Min;
import org.elasticsearch.search.aggregations.metrics.Sum;
import org.elasticsearch.search.aggregations.pipeline.InternalBucketMetricValue;
import org.elasticsearch.search.aggregations.pipeline.InternalPercentilesBucket;
Expand Down Expand Up @@ -187,8 +187,8 @@ public static boolean hasValue(InternalMedianAbsoluteDeviation agg) {
return MetricInspectionHelper.hasValue(agg);
}

public static boolean hasValue(InternalMin agg) {
return agg.getValue() != Double.POSITIVE_INFINITY;
public static boolean hasValue(Min agg) {
return agg.value() != Double.POSITIVE_INFINITY;
}

public static boolean hasValue(InternalScriptedMetric agg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentilesRanksTests;
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentilesTests;
import org.elasticsearch.search.aggregations.metrics.InternalMedianAbsoluteDeviationTests;
import org.elasticsearch.search.aggregations.metrics.InternalMinTests;
import org.elasticsearch.search.aggregations.metrics.InternalScriptedMetricTests;
import org.elasticsearch.search.aggregations.metrics.InternalStatsBucketTests;
import org.elasticsearch.search.aggregations.metrics.InternalStatsTests;
Expand All @@ -57,6 +56,7 @@
import org.elasticsearch.search.aggregations.metrics.InternalValueCountTests;
import org.elasticsearch.search.aggregations.metrics.InternalWeightedAvgTests;
import org.elasticsearch.search.aggregations.metrics.MaxTests;
import org.elasticsearch.search.aggregations.metrics.MinTests;
import org.elasticsearch.search.aggregations.metrics.SumTests;
import org.elasticsearch.search.aggregations.pipeline.InternalBucketMetricValueTests;
import org.elasticsearch.search.aggregations.pipeline.InternalDerivativeTests;
Expand Down Expand Up @@ -102,7 +102,7 @@ public class AggregationsTests extends ESTestCase {
new InternalHDRPercentilesTests(),
new InternalHDRPercentilesRanksTests(),
new InternalPercentilesBucketTests(),
new InternalMinTests(),
new MinTests(),
new MaxTests(),
new InternalAvgTests(),
new InternalWeightedAvgTests(),
Expand Down

0 comments on commit dc8ec42

Please sign in to comment.