Skip to content

Commit dd5c31b

Browse files
authored
Implement WithFieldName interface in ValuesSourceAggregationBuilder & FieldSortBuilder (#15916) (#15970)
Signed-off-by: David Zane <[email protected]> (cherry picked from commit 7c427d9)
1 parent af25ece commit dd5c31b

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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
- [Offline Nodes] Adds offline-tasks library containing various interfaces to be used for Offline Background Tasks. ([#13574](https://github.com/opensearch-project/OpenSearch/pull/13574))
99
- Add path prefix support to hashed prefix snapshots ([#15664](https://github.com/opensearch-project/OpenSearch/pull/15664))
1010
- [Workload Management] QueryGroup resource cancellation framework changes ([#15651](https://github.com/opensearch-project/OpenSearch/pull/15651))
11+
- Implement WithFieldName interface in ValuesSourceAggregationBuilder & FieldSortBuilder ([#15916](https://github.com/opensearch-project/OpenSearch/pull/15916))
1112

1213
### Dependencies
1314
- Bump `org.apache.logging.log4j:log4j-core` from 2.23.1 to 2.24.0 ([#15858](https://github.com/opensearch-project/OpenSearch/pull/15858))

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.opensearch.core.xcontent.XContentBuilder;
4444
import org.opensearch.core.xcontent.XContentParser;
4545
import org.opensearch.index.query.QueryShardContext;
46+
import org.opensearch.index.query.WithFieldName;
4647
import org.opensearch.script.Script;
4748
import org.opensearch.search.aggregations.AbstractAggregationBuilder;
4849
import org.opensearch.search.aggregations.AggregationInitializationException;
@@ -60,7 +61,9 @@
6061
*
6162
* @opensearch.internal
6263
*/
63-
public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggregationBuilder<AB>> extends AbstractAggregationBuilder<AB> {
64+
public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggregationBuilder<AB>> extends AbstractAggregationBuilder<AB>
65+
implements
66+
WithFieldName {
6467

6568
public static <T> void declareFields(
6669
AbstractObjectParser<? extends ValuesSourceAggregationBuilder<?>, T> objectParser,
@@ -303,6 +306,11 @@ public String field() {
303306
return field;
304307
}
305308

309+
@Override
310+
public String fieldName() {
311+
return field();
312+
}
313+
306314
/**
307315
* Sets the script to use for this aggregation.
308316
*/

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.opensearch.index.query.QueryRewriteContext;
6767
import org.opensearch.index.query.QueryShardContext;
6868
import org.opensearch.index.query.QueryShardException;
69+
import org.opensearch.index.query.WithFieldName;
6970
import org.opensearch.search.DocValueFormat;
7071
import org.opensearch.search.MultiValueMode;
7172
import org.opensearch.search.SearchSortValuesAndFormats;
@@ -87,7 +88,7 @@
8788
*
8889
* @opensearch.internal
8990
*/
90-
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
91+
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> implements WithFieldName {
9192
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(FieldSortBuilder.class);
9293

9394
public static final String NAME = "field_sort";
@@ -189,6 +190,11 @@ public String getFieldName() {
189190
return this.fieldName;
190191
}
191192

193+
@Override
194+
public String fieldName() {
195+
return getFieldName();
196+
}
197+
192198
/**
193199
* Sets the value when a field is missing in a doc. Can also be set to {@code _last} or
194200
* {@code _first} to sort missing last or first respectively.

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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)