Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WithFieldName interface in ValuesSourceAggregationBuilder & FieldSortBuilder #15916

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- MultiTermQueries in keyword fields now default to `indexed` approach and gated behind cluster setting ([#15637](https://github.com/opensearch-project/OpenSearch/pull/15637))
- [Workload Management] QueryGroup resource cancellation framework changes ([#15651](https://github.com/opensearch-project/OpenSearch/pull/15651))
- Fallback to Remote cluster-state on Term-Version check mismatch - ([#15424](https://github.com/opensearch-project/OpenSearch/pull/15424))
- Implement WithFieldName interface in ValuesSourceAggregationBuilder & FieldSortBuilder ([#15916](https://github.com/opensearch-project/OpenSearch/pull/15916))

### Dependencies
- Bump `com.azure:azure-identity` from 1.13.0 to 1.13.2 ([#15578](https://github.com/opensearch-project/OpenSearch/pull/15578))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.index.query.WithFieldName;
import org.opensearch.script.Script;
import org.opensearch.search.aggregations.AbstractAggregationBuilder;
import org.opensearch.search.aggregations.AggregationInitializationException;
Expand All @@ -57,7 +58,9 @@
*
* @opensearch.internal
*/
public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggregationBuilder<AB>> extends AbstractAggregationBuilder<AB> {
public abstract class ValuesSourceAggregationBuilder<AB extends ValuesSourceAggregationBuilder<AB>> extends AbstractAggregationBuilder<AB>
implements
WithFieldName {

public static <T> void declareFields(
AbstractObjectParser<? extends ValuesSourceAggregationBuilder<?>, T> objectParser,
Expand Down Expand Up @@ -292,6 +295,11 @@ public String field() {
return field;
}

@Override
public String fieldName() {
return field();
}

/**
* Sets the script to use for this aggregation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.opensearch.index.query.QueryRewriteContext;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.index.query.QueryShardException;
import org.opensearch.index.query.WithFieldName;
import org.opensearch.search.DocValueFormat;
import org.opensearch.search.MultiValueMode;
import org.opensearch.search.SearchSortValuesAndFormats;
Expand All @@ -86,7 +87,7 @@
*
* @opensearch.internal
*/
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> {
public class FieldSortBuilder extends SortBuilder<FieldSortBuilder> implements WithFieldName {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(FieldSortBuilder.class);

public static final String NAME = "field_sort";
Expand Down Expand Up @@ -184,6 +185,11 @@ public String getFieldName() {
return this.fieldName;
}

@Override
public String fieldName() {
return getFieldName();
}

/**
* Sets the value when a field is missing in a doc. Can also be set to {@code _last} or
* {@code _first} to sort missing last or first respectively.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void testNumericKeys() throws IOException {
);
assertThat(builder.getName(), equalTo("test"));
assertThat(builder.field(), equalTo("f"));
assertThat(builder.fieldName(), equalTo("f"));
assertThat(builder.ranges, equalTo(List.of(new RangeAggregator.Range("1", null, 0d))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ protected void sortFieldAssertions(FieldSortBuilder builder, SortField sortField
assertEquals(builder.order() == SortOrder.ASC ? false : true, sortField.getReverse());
if (expectedType == SortField.Type.CUSTOM) {
assertEquals(builder.getFieldName(), sortField.getField());
assertEquals(builder.fieldName(), sortField.getField());
}
assertEquals(DocValueFormat.RAW, format);
}
Expand Down
Loading