Skip to content

Commit e7d62b4

Browse files
dzane17dk2k
authored andcommitted
Implement WithFieldName interface in ValuesSourceAggregationBuilder & FieldSortBuilder (opensearch-project#15916)
Signed-off-by: David Zane <davizane@amazon.com>
1 parent 8d7735b commit e7d62b4

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88
- MultiTermQueries in keyword fields now default to `indexed` approach and gated behind cluster setting ([#15637](https://github.com/opensearch-project/OpenSearch/pull/15637))
99
- [Workload Management] QueryGroup resource cancellation framework changes ([#15651](https://github.com/opensearch-project/OpenSearch/pull/15651))
1010
- Fallback to Remote cluster-state on Term-Version check mismatch - ([#15424](https://github.com/opensearch-project/OpenSearch/pull/15424))
11+
- Implement WithFieldName interface in ValuesSourceAggregationBuilder & FieldSortBuilder ([#15916](https://github.com/opensearch-project/OpenSearch/pull/15916))
1112

1213
### Dependencies
1314
- Bump `com.azure:azure-identity` from 1.13.0 to 1.13.2 ([#15578](https://github.com/opensearch-project/OpenSearch/pull/15578))

server/src/main/java/org/opensearch/search/aggregations/support/ValuesSourceAggregationBuilder.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.opensearch.core.xcontent.XContentBuilder;
4141
import org.opensearch.core.xcontent.XContentParser;
4242
import org.opensearch.index.query.QueryShardContext;
43+
import org.opensearch.index.query.WithFieldName;
4344
import org.opensearch.script.Script;
4445
import org.opensearch.search.aggregations.AbstractAggregationBuilder;
4546
import org.opensearch.search.aggregations.AggregationInitializationException;
@@ -57,7 +58,9 @@
5758
*
5859
* @opensearch.internal
5960
*/
60-
public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggregationBuilder<AB>> extends AbstractAggregationBuilder<AB> {
61+
public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggregationBuilder<AB>> extends AbstractAggregationBuilder<AB>
62+
implements
63+
WithFieldName {
6164

6265
public static <T> void declareFields(
6366
AbstractObjectParser<? extends ValuesSourceAggregationBuilder<?>, T> objectParser,
@@ -292,6 +295,11 @@ public String field() {
292295
return field;
293296
}
294297

298+
@Override
299+
public String fieldName() {
300+
return field();
301+
}
302+
295303
/**
296304
* Sets the script to use for this aggregation.
297305
*/

server/src/main/java/org/opensearch/search/sort/FieldSortBuilder.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.opensearch.index.query.QueryRewriteContext;
6666
import org.opensearch.index.query.QueryShardContext;
6767
import org.opensearch.index.query.QueryShardException;
68+
import org.opensearch.index.query.WithFieldName;
6869
import org.opensearch.search.DocValueFormat;
6970
import org.opensearch.search.MultiValueMode;
7071
import org.opensearch.search.SearchSortValuesAndFormats;
@@ -86,7 +87,7 @@
8687
*
8788
* @opensearch.internal
8889
*/
89-
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
90+
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> implements WithFieldName {
9091
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(FieldSortBuilder.class);
9192

9293
public static final String NAME = "field_sort";
@@ -184,6 +185,11 @@ public String getFieldName() {
184185
return this.fieldName;
185186
}
186187

188+
@Override
189+
public String fieldName() {
190+
return getFieldName();
191+
}
192+
187193
/**
188194
* Sets the value when a field is missing in a doc. Can also be set to {@code _last} or
189195
* {@code _first} to sort missing last or first respectively.

server/src/test/java/org/opensearch/search/aggregations/bucket/range/RangeAggregationBuilderTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void testNumericKeys() throws IOException {
128128
);
129129
assertThat(builder.getName(), equalTo("test"));
130130
assertThat(builder.field(), equalTo("f"));
131+
assertThat(builder.fieldName(), equalTo("f"));
131132
assertThat(builder.ranges, equalTo(List.of(new RangeAggregator.Range("1", null, 0d))));
132133
}
133134
}

server/src/test/java/org/opensearch/search/sort/FieldSortBuilderTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ protected void sortFieldAssertions(FieldSortBuilder builder, SortField sortField
196196
assertEquals(builder.order() == SortOrder.ASC ? false : true, sortField.getReverse());
197197
if (expectedType == SortField.Type.CUSTOM) {
198198
assertEquals(builder.getFieldName(), sortField.getField());
199+
assertEquals(builder.fieldName(), sortField.getField());
199200
}
200201
assertEquals(DocValueFormat.RAW, format);
201202
}

0 commit comments

Comments
 (0)