Skip to content

Commit a85f893

Browse files
authored
Remove version conditionals from InternalAggregations (#40193)
* Remove version conditionals from InternalAggregations Version conditionals are no longer needed once #40177 is back-ported all the way to 6.7. * Disable bwc tests Relates to #40177 * indentation
1 parent 1f62a7a commit a85f893

File tree

3 files changed

+11
-49
lines changed

3 files changed

+11
-49
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ task verifyVersions {
162162
* after the backport of the backcompat code is complete.
163163
*/
164164

165-
boolean bwc_tests_enabled = true
166-
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
165+
boolean bwc_tests_enabled = false
166+
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/40177" /* place a PR link here when committing bwc changes */
167167
if (bwc_tests_enabled == false) {
168168
if (bwc_tests_disabled_issue.isEmpty()) {
169169
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")

server/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.elasticsearch.search.aggregations;
2020

21-
import org.elasticsearch.Version;
2221
import org.elasticsearch.common.io.stream.StreamInput;
2322
import org.elasticsearch.common.io.stream.StreamOutput;
2423
import org.elasticsearch.common.io.stream.Streamable;
@@ -150,22 +149,14 @@ public void readFrom(StreamInput in) throws IOException {
150149
if (aggregations.isEmpty()) {
151150
aggregationsAsMap = emptyMap();
152151
}
153-
//TODO update version after backport
154-
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
155-
this.topLevelPipelineAggregators = in.readList(
152+
this.topLevelPipelineAggregators = in.readList(
156153
stream -> (SiblingPipelineAggregator)in.readNamedWriteable(PipelineAggregator.class));
157-
} else {
158-
this.topLevelPipelineAggregators = Collections.emptyList();
159-
}
160154
}
161155

162156
@Override
163157
@SuppressWarnings("unchecked")
164158
public void writeTo(StreamOutput out) throws IOException {
165159
out.writeNamedWriteableList((List<InternalAggregation>)aggregations);
166-
//TODO update version after backport
167-
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
168-
out.writeNamedWriteableList(topLevelPipelineAggregators);
169-
}
160+
out.writeNamedWriteableList(topLevelPipelineAggregators);
170161
}
171162
}

server/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationsTests.java

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,19 @@
2626
import org.elasticsearch.common.settings.Settings;
2727
import org.elasticsearch.search.DocValueFormat;
2828
import org.elasticsearch.search.SearchModule;
29-
import org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogram;
3029
import org.elasticsearch.search.aggregations.bucket.histogram.InternalDateHistogramTests;
3130
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
3231
import org.elasticsearch.search.aggregations.bucket.terms.StringTermsTests;
3332
import org.elasticsearch.search.aggregations.pipeline.AvgBucketPipelineAggregationBuilder;
34-
import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue;
3533
import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValueTests;
3634
import org.elasticsearch.search.aggregations.pipeline.MaxBucketPipelineAggregationBuilder;
3735
import org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator;
3836
import org.elasticsearch.search.aggregations.pipeline.SumBucketPipelineAggregationBuilder;
3937
import org.elasticsearch.test.ESTestCase;
4038
import org.elasticsearch.test.VersionUtils;
41-
import org.hamcrest.Matchers;
4239

4340
import java.io.IOException;
4441
import java.util.ArrayList;
45-
import java.util.Base64;
4642
import java.util.Collections;
4743
import java.util.List;
4844

@@ -136,18 +132,13 @@ private void writeToAndReadFrom(InternalAggregations aggregations, int iteration
136132
if (aggregations.getTopLevelPipelineAggregators() == null) {
137133
assertEquals(0, deserialized.getTopLevelPipelineAggregators().size());
138134
} else {
139-
//TODO update version after backport
140-
if (version.before(Version.V_8_0_0)) {
141-
assertEquals(0, deserialized.getTopLevelPipelineAggregators().size());
142-
} else {
143-
assertEquals(aggregations.getTopLevelPipelineAggregators().size(),
144-
deserialized.getTopLevelPipelineAggregators().size());
145-
for (int i = 0; i < aggregations.getTopLevelPipelineAggregators().size(); i++) {
146-
SiblingPipelineAggregator siblingPipelineAggregator1 = aggregations.getTopLevelPipelineAggregators().get(i);
147-
SiblingPipelineAggregator siblingPipelineAggregator2 = deserialized.getTopLevelPipelineAggregators().get(i);
148-
assertArrayEquals(siblingPipelineAggregator1.bucketsPaths(), siblingPipelineAggregator2.bucketsPaths());
149-
assertEquals(siblingPipelineAggregator1.name(), siblingPipelineAggregator2.name());
150-
}
135+
assertEquals(aggregations.getTopLevelPipelineAggregators().size(),
136+
deserialized.getTopLevelPipelineAggregators().size());
137+
for (int i = 0; i < aggregations.getTopLevelPipelineAggregators().size(); i++) {
138+
SiblingPipelineAggregator siblingPipelineAggregator1 = aggregations.getTopLevelPipelineAggregators().get(i);
139+
SiblingPipelineAggregator siblingPipelineAggregator2 = deserialized.getTopLevelPipelineAggregators().get(i);
140+
assertArrayEquals(siblingPipelineAggregator1.bucketsPaths(), siblingPipelineAggregator2.bucketsPaths());
141+
assertEquals(siblingPipelineAggregator1.name(), siblingPipelineAggregator2.name());
151142
}
152143
}
153144
if (iteration < 2) {
@@ -157,24 +148,4 @@ private void writeToAndReadFrom(InternalAggregations aggregations, int iteration
157148
}
158149
}
159150
}
160-
161-
//TODO update version and rename after backport
162-
public void testSerializationFromPre_8_0_0() throws IOException {
163-
String aggsString = "AwZzdGVybXMFb0F0Q0EKCQVsZG5ncgAFeG56RWcFeUFxVmcABXBhQVVpBUtYc2VIAAVaclRESwVqUkxySAAFelp5d1AFRUREcEYABW1" +
164-
"sckF0BU5wWWVFAAVJYVJmZgVURlJVbgAFT0RiU04FUWNwSVoABU1sb09HBUNzZHFlAAVWWmJHaQABAwGIDgNyYXcFAQAADmRhdGVfaGlzdG9ncmFt" +
165-
"BVhHbVl4/wADAAKAurcDA1VUQwABAQAAAWmOhukAAQAAAWmR9dEAAAAAAAAAAAAAAANyYXcACAAAAWmQrDoAUQAAAAFpkRoXAEMAAAABaZGH9AAtA" +
166-
"AAAAWmR9dEAJwAAAAFpkmOuAFwAAAABaZLRiwAYAAAAAWmTP2gAKgAAAAFpk61FABsADHNpbXBsZV92YWx1ZQVsWVNLVv8AB2RlY2ltYWwGIyMjLi" +
167-
"MjQLZWZVy5zBYAAAAAAAAAAAAAAAAAAAAAAAAA";
168-
169-
byte[] aggsBytes = Base64.getDecoder().decode(aggsString);
170-
try (NamedWriteableAwareStreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(aggsBytes), registry)) {
171-
in.setVersion(VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(),
172-
Version.max(Version.CURRENT.minimumCompatibilityVersion(), VersionUtils.getPreviousVersion(Version.CURRENT))));
173-
InternalAggregations deserialized = InternalAggregations.readAggregations(in);
174-
assertEquals(3, deserialized.aggregations.size());
175-
assertThat(deserialized.aggregations.get(0), Matchers.instanceOf(StringTerms.class));
176-
assertThat(deserialized.aggregations.get(1), Matchers.instanceOf(InternalDateHistogram.class));
177-
assertThat(deserialized.aggregations.get(2), Matchers.instanceOf(InternalSimpleValue.class));
178-
}
179-
}
180151
}

0 commit comments

Comments
 (0)