Skip to content

Commit 726e6c4

Browse files
authored
Move getType to Aggregation interface (#24822)
Given that both InternalAggregation and ParsedAggregation have this method, it makes sense to move it to the interface they both implement.
1 parent db04903 commit 726e6c4

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

core/src/main/java/org/elasticsearch/search/aggregations/Aggregation.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public interface Aggregation extends ToXContent {
3939
*/
4040
String getName();
4141

42+
/**
43+
* @return a string representing the type of the aggregation. This type is added to
44+
* the aggregation name in the response, so that it can later be used by clients
45+
* to determine type of the aggregation and parse it into the proper object.
46+
*/
47+
String getType();
48+
4249
/**
4350
* Get the optional byte array metadata that was set on the aggregation
4451
*/

core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,7 @@ public List<PipelineAggregator> pipelineAggregators() {
169169
return pipelineAggregators;
170170
}
171171

172-
/**
173-
* Returns a string representing the type of the aggregation. This type is added to
174-
* the aggregation name in the response, so that it can later be used by REST clients
175-
* to determine the internal type of the aggregation.
176-
*/
172+
@Override
177173
public String getType() {
178174
return getWriteableName();
179175
}

core/src/main/java/org/elasticsearch/search/aggregations/ParsedAggregation.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ public final Map<String, Object> getMetaData() {
5757
return metadata;
5858
}
5959

60-
/**
61-
* Returns a string representing the type of the aggregation. This type is added to
62-
* the aggregation name in the response, so that it can later be used by REST clients
63-
* to determine the internal type of the aggregation.
64-
*/
65-
//TODO it may make sense to move getType to the Aggregation interface given that we are duplicating it in both implementations
66-
public abstract String getType();
67-
6860
@Override
6961
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
7062
// Concatenates the type and the name of the aggregation (ex: top_hits#foo)

core/src/test/java/org/elasticsearch/search/aggregations/InternalMultiBucketAggregationTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected void assertMultiBucketsAggregation(MultiBucketsAggregation expected, M
122122
assertTrue(expected instanceof InternalAggregation);
123123
assertEquals(expected.getName(), actual.getName());
124124
assertEquals(expected.getMetaData(), actual.getMetaData());
125-
assertEquals(((InternalAggregation) expected).getType(), ((ParsedAggregation) actual).getType());
125+
assertEquals(expected.getType(), actual.getType());
126126
}
127127

128128
protected void assertBucket(MultiBucketsAggregation.Bucket expected, MultiBucketsAggregation.Bucket actual, boolean checkOrder) {

test/framework/src/main/java/org/elasticsearch/test/InternalAggregationTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ protected <P extends ParsedAggregation> P parseAndAssert(final InternalAggregati
333333
assertEquals(aggregation.getMetaData(), parsedAggregation.getMetaData());
334334

335335
assertTrue(parsedAggregation instanceof ParsedAggregation);
336-
assertEquals(aggregation.getType(), ((ParsedAggregation) parsedAggregation).getType());
336+
assertEquals(aggregation.getType(), parsedAggregation.getType());
337337
}
338338

339339
BytesReference parsedBytes = toXContent(parsedAggregation, xContentType, params, humanReadable);

0 commit comments

Comments
 (0)