Skip to content

Commit

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

Related to #82273
  • Loading branch information
nik9000 authored Feb 28, 2022
1 parent 3c66958 commit 8cbcace
Show file tree
Hide file tree
Showing 50 changed files with 388 additions and 425 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.elasticsearch.search.aggregations.LeafBucketCollector;
import org.elasticsearch.search.aggregations.bucket.terms.LongTerms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.InternalMax;
import org.elasticsearch.search.aggregations.metrics.Max;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.builder.SearchSourceBuilder;
Expand Down Expand Up @@ -78,7 +78,7 @@ public static class TestPlugin extends Plugin implements SearchPlugin {
public List<AggregationSpec> getAggregations() {
return Collections.singletonList(
new AggregationSpec(TestAggregationBuilder.NAME, TestAggregationBuilder::new, TestAggregationBuilder.PARSER)
.addResultReader(InternalMax::new)
.addResultReader(Max::new)
);
}

Expand Down Expand Up @@ -687,7 +687,7 @@ public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws I

@Override
public InternalAggregation buildEmptyAggregation() {
return new InternalMax(name(), Double.NaN, DocValueFormat.RAW, null);
return new Max(name(), Double.NaN, DocValueFormat.RAW, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void testIssue10719() throws Exception {
for (Terms.Bucket genreBucket : genres.getBuckets()) {
Sampler sample = genreBucket.getAggregations().get("sample");
Max maxPriceInGenre = sample.getAggregations().get("max_price");
double price = maxPriceInGenre.getValue();
double price = maxPriceInGenre.value();
if (asc) {
assertThat(price, greaterThanOrEqualTo(lastMaxPrice));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ public void testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels(
assertThat(filter2.getDocCount(), equalTo(asc ? 3L : 2L));
Max max = filter2.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getValue(), equalTo(asc ? 2.0 : 4.0));
assertThat(max.value(), equalTo(asc ? 2.0 : 4.0));

tag = iters.next();
assertThat(tag, notNullValue());
Expand All @@ -665,7 +665,7 @@ public void testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels(
assertThat(filter2.getDocCount(), equalTo(asc ? 2L : 3L));
max = filter2.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getValue(), equalTo(asc ? 4.0 : 2.0));
assertThat(max.value(), equalTo(asc ? 4.0 : 2.0));
}

public void testSingleValuedFieldOrderedByMissingSubAggregation() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ public void testSingleValuedFieldOrderedBySubAggregationDescDeepOrderPath() thro
assertThat(bucket.getDocCount(), equalTo(filter.getDocCount()));
Max max = filter.getAggregations().get("max");
assertThat(max, Matchers.notNullValue());
assertThat(max.getValue(), asc ? greaterThanOrEqualTo(prevMax) : lessThanOrEqualTo(prevMax));
prevMax = max.getValue();
assertThat(max.value(), asc ? greaterThanOrEqualTo(prevMax) : lessThanOrEqualTo(prevMax));
prevMax = max.value();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ public void testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels(
assertThat(filter2.getDocCount(), equalTo(asc ? 3L : 2L));
Max max = filter2.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getValue(), equalTo(asc ? 2.0 : 4.0));
assertThat(max.value(), equalTo(asc ? 2.0 : 4.0));

tag = iters.next();
assertThat(tag, notNullValue());
Expand All @@ -655,7 +655,7 @@ public void testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels(
assertThat(filter2.getDocCount(), equalTo(asc ? 2L : 3L));
max = filter2.getAggregations().get("max");
assertThat(max, notNullValue());
assertThat(max.getValue(), equalTo(asc ? 4.0 : 2.0));
assertThat(max.value(), equalTo(asc ? 4.0 : 2.0));
}

public void testSingleValuedFieldOrderedByMissingSubAggregation() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void testNestedAsSubAggregation() throws Exception {
assertThat(nested, notNullValue());
Max max = nested.getAggregations().get("max_value");
assertThat(max, notNullValue());
assertThat(max.getValue(), equalTo(numChildren[i] == 0 ? Double.NEGATIVE_INFINITY : (double) i + numChildren[i]));
assertThat(max.value(), equalTo(numChildren[i] == 0 ? Double.NEGATIVE_INFINITY : (double) i + numChildren[i]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void testIssue10719() throws Exception {
for (Terms.Bucket genreBucket : genres.getBuckets()) {
Sampler sample = genreBucket.getAggregations().get("sample");
Max maxPriceInGenre = sample.getAggregations().get("max_price");
double price = maxPriceInGenre.getValue();
double price = maxPriceInGenre.value();
if (asc) {
assertThat(price, greaterThanOrEqualTo(lastMaxPrice));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ public void testSortByBucket() throws Exception {
assertThat(hits.getAt(1).getSortValues()[0], equalTo(higestSortValue - 1));
assertThat(hits.getAt(2).getSortValues()[0], equalTo(higestSortValue - 2));
Max max = bucket.getAggregations().get("max_sort");
assertThat(max.getValue(), equalTo(((Long) higestSortValue).doubleValue()));
assertThat(max.value(), equalTo(((Long) higestSortValue).doubleValue()));
higestSortValue -= 10;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@
import org.elasticsearch.search.aggregations.metrics.InternalGeoCentroid;
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentileRanks;
import org.elasticsearch.search.aggregations.metrics.InternalHDRPercentiles;
import org.elasticsearch.search.aggregations.metrics.InternalMax;
import org.elasticsearch.search.aggregations.metrics.InternalMedianAbsoluteDeviation;
import org.elasticsearch.search.aggregations.metrics.InternalMin;
import org.elasticsearch.search.aggregations.metrics.InternalScriptedMetric;
Expand All @@ -180,6 +179,7 @@
import org.elasticsearch.search.aggregations.metrics.InternalTopHits;
import org.elasticsearch.search.aggregations.metrics.InternalValueCount;
import org.elasticsearch.search.aggregations.metrics.InternalWeightedAvg;
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.MinAggregationBuilder;
Expand Down Expand Up @@ -394,7 +394,7 @@ private ValuesSourceRegistry registerAggregations(List<SearchPlugin> plugins) {
);
registerAggregation(
new AggregationSpec(MaxAggregationBuilder.NAME, MaxAggregationBuilder::new, MaxAggregationBuilder.PARSER).addResultReader(
InternalMax::new
Max::new
).setAggregatorRegistrar(MaxAggregationBuilder::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 maximum of the values in the current bucket.
*/
public interface Max 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 Max extends InternalNumericMetricsAggregation.SingleValue {
private final double max;

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

/**
* The maximum.
* Read from a stream.
*/
double getValue();
public Max(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
max = in.readDouble();
}

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

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

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

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

@Override
public Max reduce(List<InternalAggregation> aggregations, AggregationReduceContext reduceContext) {
double max = Double.NEGATIVE_INFINITY;
for (InternalAggregation aggregation : aggregations) {
max = Math.max(max, ((Max) aggregation).max);
}
return new Max(name, max, format, getMetadata());
}

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

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

@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;
Max other = (Max) obj;
return Objects.equals(max, other.max);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ public InternalAggregation buildAggregation(long bucket) {
if (valuesSource == null || bucket >= maxes.size()) {
return buildEmptyAggregation();
}
return new InternalMax(name, maxes.get(bucket), formatter, metadata());
return new Max(name, maxes.get(bucket), formatter, metadata());
}

@Override
public InternalAggregation buildEmptyAggregation() {
return new InternalMax(name, Double.NEGATIVE_INFINITY, formatter, metadata());
return new Max(name, Double.NEGATIVE_INFINITY, formatter, 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 ParsedMax extends ParsedSingleValueNumericMetricsAggregation implements Max {

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

public class ParsedMax extends ParsedSingleValueNumericMetricsAggregation {
@Override
public String getType() {
return MaxAggregationBuilder.NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationReduceContext;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.metrics.InternalMax;
import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation;
import org.elasticsearch.search.aggregations.metrics.Max;
import org.elasticsearch.search.aggregations.metrics.Percentile;
import org.elasticsearch.xcontent.XContentBuilder;

Expand Down Expand Up @@ -130,7 +130,7 @@ public Iterable<String> valueNames() {
}

@Override
public InternalMax reduce(List<InternalAggregation> aggregations, AggregationReduceContext reduceContext) {
public Max reduce(List<InternalAggregation> aggregations, AggregationReduceContext reduceContext) {
throw new UnsupportedOperationException("Not supported");
}

Expand Down
Loading

0 comments on commit 8cbcace

Please sign in to comment.