Skip to content
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 @@ -48,6 +48,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add failureaccess as runtime dependency to transport-grpc module ([#19339](https://github.com/opensearch-project/OpenSearch/pull/19339))
- Migrate usages of deprecated `Operations#union` from Lucene ([#19397](https://github.com/opensearch-project/OpenSearch/pull/19397))
- Delegate primitive write methods with ByteSizeCachingDirectory wrapped IndexOutput ([#19432](https://github.com/opensearch-project/OpenSearch/pull/19432))
- Bump opensearch-protobufs dependency to 0.18.0 and update transport-grpc module compatibility ([#19447](https://github.com/opensearch-project/OpenSearch/issues/19447))

### Fixed
- Fix unnecessary refreshes on update preparation failures ([#15261](https://github.com/opensearch-project/OpenSearch/issues/15261))
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kotlin = "1.7.10"
antlr4 = "4.13.1"
guava = "33.2.1-jre"
gson = "2.13.2"
opensearchprotobufs = "0.13.0"
opensearchprotobufs = "0.18.0"
protobuf = "3.25.8"
jakarta_annotation = "1.3.5"
google_http_client = "1.44.1"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e8dc93c60df892184d7c2010e1bd4f15a777c292

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e8dc93c60df892184d7c2010e1bd4f15a777c292
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ private QueryContainer createMockTermQueryContainer() {
* Helper method to create a mock range query container
*/
private QueryContainer createMockRangeQueryContainer() {
return QueryContainer.newBuilder()
.setRange(org.opensearch.protobufs.RangeQuery.newBuilder().setField("range_field").build())
.build();
return QueryContainer.newBuilder().setRange(org.opensearch.protobufs.RangeQuery.newBuilder().build()).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public static FetchSourceContext parseFromProtoRequest(org.opensearch.protobufs.
// Set up source context if source parameters are provided
if (request.hasXSource()) {
switch (request.getXSource().getSourceConfigParamCase()) {
case BOOL_VALUE:
fetchSource = request.getXSource().getBoolValue();
case BOOL:
fetchSource = request.getXSource().getBool();
break;
case STRING_ARRAY:
sourceIncludes = request.getXSource().getStringArray().getStringArrayList().toArray(new String[0]);
Expand Down Expand Up @@ -84,8 +84,8 @@ public static FetchSourceContext parseFromProtoRequest(org.opensearch.protobufs.
if (request.hasXSource()) {
SourceConfigParam source = request.getXSource();

if (source.hasBoolValue()) {
fetchSource = source.getBoolValue();
if (source.hasBool()) {
fetchSource = source.getBool();
} else {
sourceIncludes = source.getStringArray().getStringArrayList().toArray(new String[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static ActiveShardCount parseProto(WaitForActiveShards waitForActiveShard
default:
return ActiveShardCount.DEFAULT;
}
case INT32_VALUE:
return ActiveShardCount.from(waitForActiveShards.getInt32Value());
case INT32:
return ActiveShardCount.from(waitForActiveShards.getInt32());
case WAITFORACTIVESHARDS_NOT_SET:
default:
return ActiveShardCount.DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
package org.opensearch.transport.grpc.proto.request.search;

import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.query.InnerHitBuilder;
import org.opensearch.protobufs.FieldCollapse;
import org.opensearch.search.collapse.CollapseBuilder;

import java.io.IOException;
import java.util.List;

/**
* Utility class for converting CollapseBuilder Protocol Buffers to OpenSearch objects.
Expand Down Expand Up @@ -43,7 +45,8 @@ protected static CollapseBuilder fromProto(FieldCollapse collapseProto) throws I
collapseBuilder.setMaxConcurrentGroupRequests(collapseProto.getMaxConcurrentGroupSearches());
}
if (collapseProto.getInnerHitsCount() > 0) {
collapseBuilder.setInnerHits(InnerHitsBuilderProtoUtils.fromProto(collapseProto.getInnerHitsList()));
List<InnerHitBuilder> innerHitBuilders = InnerHitsBuilderProtoUtils.fromProto(collapseProto.getInnerHitsList());
collapseBuilder.setInnerHits(innerHitBuilders);
}

return collapseBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.opensearch.transport.grpc.proto.request.search;

import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.query.InnerHitBuilder;
import org.opensearch.protobufs.InnerHits;
import org.opensearch.protobufs.ScriptField;
Expand All @@ -34,84 +33,109 @@ private InnerHitsBuilderProtoUtils() {
}

/**
* Similar to {@link InnerHitBuilder#fromXContent(XContentParser)}
* Converts a single protobuf InnerHits to an OpenSearch InnerHitBuilder.
* Each InnerHits protobuf message represents ONE inner hit definition.
*
* @param innerHits
* @param innerHits the protobuf InnerHits to convert
* @return the converted OpenSearch InnerHitBuilder
* @throws IOException if there's an error during parsing
*/
protected static InnerHitBuilder fromProto(List<InnerHits> innerHits) throws IOException {
public static InnerHitBuilder fromProto(InnerHits innerHits) throws IOException {
if (innerHits == null) {
throw new IllegalArgumentException("InnerHits cannot be null");
}

InnerHitBuilder innerHitBuilder = new InnerHitBuilder();

for (InnerHits innerHit : innerHits) {
if (innerHit.hasName()) {
innerHitBuilder.setName(innerHit.getName());
}
if (innerHit.hasIgnoreUnmapped()) {
innerHitBuilder.setIgnoreUnmapped(innerHit.getIgnoreUnmapped());
}
if (innerHit.hasFrom()) {
innerHitBuilder.setFrom(innerHit.getFrom());
}
if (innerHit.hasSize()) {
innerHitBuilder.setSize(innerHit.getSize());
}
if (innerHit.hasExplain()) {
innerHitBuilder.setExplain(innerHit.getExplain());
}
if (innerHit.hasVersion()) {
innerHitBuilder.setVersion(innerHit.getVersion());
}
if (innerHit.hasSeqNoPrimaryTerm()) {
innerHitBuilder.setSeqNoAndPrimaryTerm(innerHit.getSeqNoPrimaryTerm());
}
if (innerHit.hasTrackScores()) {
innerHitBuilder.setTrackScores(innerHit.getTrackScores());
}
if (innerHit.getStoredFieldsCount() > 0) {
innerHitBuilder.setStoredFieldNames(innerHit.getStoredFieldsList());
}
if (innerHit.getDocvalueFieldsCount() > 0) {
List<FieldAndFormat> fieldAndFormatList = new ArrayList<>();
for (org.opensearch.protobufs.FieldAndFormat fieldAndFormat : innerHit.getDocvalueFieldsList()) {
fieldAndFormatList.add(FieldAndFormatProtoUtils.fromProto(fieldAndFormat));
}
innerHitBuilder.setDocValueFields(fieldAndFormatList);
}
if (innerHit.getFieldsCount() > 0) {
List<FieldAndFormat> fieldAndFormatList = new ArrayList<>();
// TODO: this is not correct, we need to use FieldAndFormatProtoUtils.fromProto() and fix the protobufs in 0.11.0
for (String fieldName : innerHit.getFieldsList()) {
fieldAndFormatList.add(new FieldAndFormat(fieldName, null));
}
innerHitBuilder.setFetchFields(fieldAndFormatList);
}
if (innerHit.getScriptFieldsCount() > 0) {
Set<SearchSourceBuilder.ScriptField> scriptFields = new HashSet<>();
for (Map.Entry<String, ScriptField> entry : innerHit.getScriptFieldsMap().entrySet()) {
String name = entry.getKey();
ScriptField scriptFieldProto = entry.getValue();
SearchSourceBuilder.ScriptField scriptField = SearchSourceBuilderProtoUtils.ScriptFieldProtoUtils.fromProto(
name,
scriptFieldProto
);
scriptFields.add(scriptField);
}
innerHitBuilder.setScriptFields(scriptFields);
}
if (innerHit.getSortCount() > 0) {
innerHitBuilder.setSorts(SortBuilderProtoUtils.fromProto(innerHit.getSortList()));
}
if (innerHit.hasXSource()) {
innerHitBuilder.setFetchSourceContext(FetchSourceContextProtoUtils.fromProto(innerHit.getXSource()));
}
if (innerHit.hasHighlight()) {
innerHitBuilder.setHighlightBuilder(HighlightBuilderProtoUtils.fromProto(innerHit.getHighlight()));
if (innerHits.hasName()) {
innerHitBuilder.setName(innerHits.getName());
}
if (innerHits.hasIgnoreUnmapped()) {
innerHitBuilder.setIgnoreUnmapped(innerHits.getIgnoreUnmapped());
}
if (innerHits.hasFrom()) {
innerHitBuilder.setFrom(innerHits.getFrom());
}
if (innerHits.hasSize()) {
innerHitBuilder.setSize(innerHits.getSize());
}
if (innerHits.hasExplain()) {
innerHitBuilder.setExplain(innerHits.getExplain());
}
if (innerHits.hasVersion()) {
innerHitBuilder.setVersion(innerHits.getVersion());
}
if (innerHits.hasSeqNoPrimaryTerm()) {
innerHitBuilder.setSeqNoAndPrimaryTerm(innerHits.getSeqNoPrimaryTerm());
}
if (innerHits.hasTrackScores()) {
innerHitBuilder.setTrackScores(innerHits.getTrackScores());
}
if (innerHits.getStoredFieldsCount() > 0) {
innerHitBuilder.setStoredFieldNames(innerHits.getStoredFieldsList());
}
if (innerHits.getDocvalueFieldsCount() > 0) {
List<FieldAndFormat> fieldAndFormatList = new ArrayList<>();
for (org.opensearch.protobufs.FieldAndFormat fieldAndFormat : innerHits.getDocvalueFieldsList()) {
fieldAndFormatList.add(FieldAndFormatProtoUtils.fromProto(fieldAndFormat));
}
if (innerHit.hasCollapse()) {
innerHitBuilder.setInnerCollapse(CollapseBuilderProtoUtils.fromProto(innerHit.getCollapse()));
innerHitBuilder.setDocValueFields(fieldAndFormatList);
}
if (innerHits.getFieldsCount() > 0) {
List<FieldAndFormat> fieldAndFormatList = new ArrayList<>();
// TODO: this is not correct, we need to use FieldAndFormatProtoUtils.fromProto() and fix the protobufs in 0.11.0
for (String fieldName : innerHits.getFieldsList()) {
fieldAndFormatList.add(new FieldAndFormat(fieldName, null));
}
innerHitBuilder.setFetchFields(fieldAndFormatList);
}
if (innerHits.getScriptFieldsCount() > 0) {
Set<SearchSourceBuilder.ScriptField> scriptFields = new HashSet<>();
for (Map.Entry<String, ScriptField> entry : innerHits.getScriptFieldsMap().entrySet()) {
String name = entry.getKey();
ScriptField scriptFieldProto = entry.getValue();
SearchSourceBuilder.ScriptField scriptField = SearchSourceBuilderProtoUtils.ScriptFieldProtoUtils.fromProto(
name,
scriptFieldProto
);
scriptFields.add(scriptField);
}
innerHitBuilder.setScriptFields(scriptFields);
}
if (innerHits.getSortCount() > 0) {
innerHitBuilder.setSorts(SortBuilderProtoUtils.fromProto(innerHits.getSortList()));
}
if (innerHits.hasXSource()) {
innerHitBuilder.setFetchSourceContext(FetchSourceContextProtoUtils.fromProto(innerHits.getXSource()));
}
if (innerHits.hasHighlight()) {
innerHitBuilder.setHighlightBuilder(HighlightBuilderProtoUtils.fromProto(innerHits.getHighlight()));
}
if (innerHits.hasCollapse()) {
innerHitBuilder.setInnerCollapse(CollapseBuilderProtoUtils.fromProto(innerHits.getCollapse()));
}

return innerHitBuilder;
}

/**
* Converts a list of protobuf InnerHits to a list of OpenSearch InnerHitBuilder objects.
* Each InnerHits protobuf message represents ONE inner hit definition.
*
* @param innerHitsList the list of protobuf InnerHits to convert
* @return the list of converted OpenSearch InnerHitBuilder objects
* @throws IOException if there's an error during parsing
*/
public static List<InnerHitBuilder> fromProto(List<InnerHits> innerHitsList) throws IOException {
if (innerHitsList == null) {
throw new IllegalArgumentException("InnerHits list cannot be null");
}

List<InnerHitBuilder> innerHitBuilders = new ArrayList<>();
for (InnerHits innerHits : innerHitsList) {
innerHitBuilders.add(fromProto(innerHits));
}
return innerHitBuilders;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.opensearch.search.fetch.StoredFieldsContext;
import org.opensearch.search.fetch.subphase.FetchSourceContext;
import org.opensearch.search.internal.SearchContext;
import org.opensearch.search.sort.SortOrder;
import org.opensearch.search.suggest.SuggestBuilder;
import org.opensearch.transport.client.Client;
import org.opensearch.transport.client.node.NodeClient;
Expand Down Expand Up @@ -271,28 +270,6 @@ protected static void parseSearchSource(
}
}

if (request.getSortCount() > 0) {
for (SearchRequest.SortOrder sort : request.getSortList()) {
String sortField = sort.getField();

if (sort.hasDirection()) {
SearchRequest.SortOrder.Direction direction = sort.getDirection();
switch (direction) {
case DIRECTION_ASC:
searchSourceBuilder.sort(sortField, SortOrder.ASC);
break;
case DIRECTION_DESC:
searchSourceBuilder.sort(sortField, SortOrder.DESC);
break;
default:
throw new IllegalArgumentException("Unsupported sort direction " + direction.toString());
}
} else {
searchSourceBuilder.sort(sortField);
}
}
}

if (request.getStatsCount() > 0) {
searchSourceBuilder.stats(request.getStatsList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package org.opensearch.transport.grpc.proto.request.search.sort;

import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.protobufs.SortOptions;
import org.opensearch.protobufs.SortCombinations;
import org.opensearch.search.sort.FieldSortBuilder;
import org.opensearch.search.sort.ScoreSortBuilder;
import org.opensearch.search.sort.SortBuilder;
Expand Down Expand Up @@ -39,31 +39,9 @@ private SortBuilderProtoUtils() {
* @throws IllegalArgumentException if invalid sort combinations are provided
* @throws UnsupportedOperationException if sort options are not yet supported
*/
public static List<SortBuilder<?>> fromProto(List<SortOptions> sortProto) {
public static List<SortBuilder<?>> fromProto(List<SortCombinations> sortProto) {
List<SortBuilder<?>> sortFields = new ArrayList<>(2);

for (SortOptions sortOptions : sortProto) {
switch (sortOptions.getSortOptionsCase()) {
case STRING:
String name = sortOptions.getString();
sortFields.add(fieldOrScoreSort(name));
break;
case SORT_OPTIONS_SCORE:
sortFields.add(new ScoreSortBuilder());
break;
case SORT_OPTIONS_DOC:
sortFields.add(new FieldSortBuilder("_doc"));
break;
case FIELD_SORT:
// Handle field sort - this is more complex and would need FieldSort parsing
throw new UnsupportedOperationException("Field sort not implemented yet");
case SORT_OPTIONS_ONE_OF:
throw new UnsupportedOperationException("Sort options oneof not supported yet");
default:
throw new IllegalArgumentException("Invalid sort options provided: " + sortOptions.getSortOptionsCase());
}
}
return sortFields;
throw new UnsupportedOperationException("sort not supported yet");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static Map.Entry<String, StringOrStringArray> headerToProto(String key, L
if (values.size() == 1) {
return new AbstractMap.SimpleEntry<String, StringOrStringArray>(
key,
StringOrStringArray.newBuilder().setStringValue(values.get(0)).build()
StringOrStringArray.newBuilder().setString(values.get(0)).build()
);
} else {
StringArray.Builder stringArrayBuilder = StringArray.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FetchSourceContextProtoUtilsTests extends OpenSearchTestCase {

public void testParseFromProtoRequestWithBoolValue() {
// Create a BulkRequest with source as boolean
BulkRequest request = BulkRequest.newBuilder().setXSource(SourceConfigParam.newBuilder().setBoolValue(true).build()).build();
BulkRequest request = BulkRequest.newBuilder().setXSource(SourceConfigParam.newBuilder().setBool(true).build()).build();

// Parse the request
FetchSourceContext context = FetchSourceContextProtoUtils.parseFromProtoRequest(request);
Expand Down Expand Up @@ -181,7 +181,7 @@ public void testFromProtoWithFilterExcludes() {

public void testParseFromProtoRequestWithSearchRequestBoolValue() {
// Create a SearchRequest with source as boolean
SearchRequest request = SearchRequest.newBuilder().setXSource(SourceConfigParam.newBuilder().setBoolValue(true).build()).build();
SearchRequest request = SearchRequest.newBuilder().setXSource(SourceConfigParam.newBuilder().setBool(true).build()).build();

// Parse the request
FetchSourceContext context = FetchSourceContextProtoUtils.parseFromProtoRequest(request);
Expand Down
Loading
Loading