Skip to content

Commit f358e81

Browse files
committed
upgrade to protobufs 0.18.0
Signed-off-by: Karen X <karenxyr@gmail.com>
1 parent 5e6ee97 commit f358e81

23 files changed

+206
-393
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4747
- Allow plugins to copy folders into their config dir during installation ([#19343](https://github.com/opensearch-project/OpenSearch/pull/19343))
4848
- Add failureaccess as runtime dependency to transport-grpc module ([#19339](https://github.com/opensearch-project/OpenSearch/pull/19339))
4949
- Migrate usages of deprecated `Operations#union` from Lucene ([#19397](https://github.com/opensearch-project/OpenSearch/pull/19397))
50+
- Bump opensearch-protobufs dependency to 0.18.0 and update transport-grpc module compatibility ([#19447](https://github.com/opensearch-project/OpenSearch/issues/19447))
5051

5152
### Fixed
5253
- Fix unnecessary refreshes on update preparation failures ([#15261](https://github.com/opensearch-project/OpenSearch/issues/15261))

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kotlin = "1.7.10"
2222
antlr4 = "4.13.1"
2323
guava = "33.2.1-jre"
2424
gson = "2.13.2"
25-
opensearchprotobufs = "0.13.0"
25+
opensearchprotobufs = "0.18.0"
2626
protobuf = "3.25.8"
2727
jakarta_annotation = "1.3.5"
2828
google_http_client = "1.44.1"

modules/transport-grpc/licenses/protobufs-0.13.0.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e8dc93c60df892184d7c2010e1bd4f15a777c292

modules/transport-grpc/spi/licenses/protobufs-0.13.0.jar.sha1

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e8dc93c60df892184d7c2010e1bd4f15a777c292

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/common/FetchSourceContextProtoUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public static FetchSourceContext parseFromProtoRequest(org.opensearch.protobufs.
4545
// Set up source context if source parameters are provided
4646
if (request.hasXSource()) {
4747
switch (request.getXSource().getSourceConfigParamCase()) {
48-
case BOOL_VALUE:
49-
fetchSource = request.getXSource().getBoolValue();
48+
case BOOL:
49+
fetchSource = request.getXSource().getBool();
5050
break;
5151
case STRING_ARRAY:
5252
sourceIncludes = request.getXSource().getStringArray().getStringArrayList().toArray(new String[0]);
@@ -84,8 +84,8 @@ public static FetchSourceContext parseFromProtoRequest(org.opensearch.protobufs.
8484
if (request.hasXSource()) {
8585
SourceConfigParam source = request.getXSource();
8686

87-
if (source.hasBoolValue()) {
88-
fetchSource = source.getBoolValue();
87+
if (source.hasBool()) {
88+
fetchSource = source.getBool();
8989
} else {
9090
sourceIncludes = source.getStringArray().getStringArrayList().toArray(new String[0]);
9191
}

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/document/bulk/ActiveShardCountProtoUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public static ActiveShardCount parseProto(WaitForActiveShards waitForActiveShard
4747
default:
4848
return ActiveShardCount.DEFAULT;
4949
}
50-
case INT32_VALUE:
51-
return ActiveShardCount.from(waitForActiveShards.getInt32Value());
50+
case INT32:
51+
return ActiveShardCount.from(waitForActiveShards.getInt32());
5252
case WAITFORACTIVESHARDS_NOT_SET:
5353
default:
5454
return ActiveShardCount.DEFAULT;

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/CollapseBuilderProtoUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
package org.opensearch.transport.grpc.proto.request.search;
99

1010
import org.opensearch.core.xcontent.XContentParser;
11+
import org.opensearch.index.query.InnerHitBuilder;
1112
import org.opensearch.protobufs.FieldCollapse;
1213
import org.opensearch.search.collapse.CollapseBuilder;
1314

1415
import java.io.IOException;
16+
import java.util.List;
1517

1618
/**
1719
* Utility class for converting CollapseBuilder Protocol Buffers to OpenSearch objects.
@@ -43,7 +45,8 @@ protected static CollapseBuilder fromProto(FieldCollapse collapseProto) throws I
4345
collapseBuilder.setMaxConcurrentGroupRequests(collapseProto.getMaxConcurrentGroupSearches());
4446
}
4547
if (collapseProto.getInnerHitsCount() > 0) {
46-
collapseBuilder.setInnerHits(InnerHitsBuilderProtoUtils.fromProto(collapseProto.getInnerHitsList()));
48+
List<InnerHitBuilder> innerHitBuilders = InnerHitsBuilderProtoUtils.fromProto(collapseProto.getInnerHitsList());
49+
collapseBuilder.setInnerHits(innerHitBuilders);
4750
}
4851

4952
return collapseBuilder;

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/InnerHitsBuilderProtoUtils.java

Lines changed: 94 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
package org.opensearch.transport.grpc.proto.request.search;
99

10-
import org.opensearch.core.xcontent.XContentParser;
1110
import org.opensearch.index.query.InnerHitBuilder;
1211
import org.opensearch.protobufs.InnerHits;
1312
import org.opensearch.protobufs.ScriptField;
@@ -34,84 +33,109 @@ private InnerHitsBuilderProtoUtils() {
3433
}
3534

3635
/**
37-
* Similar to {@link InnerHitBuilder#fromXContent(XContentParser)}
36+
* Converts a single protobuf InnerHits to an OpenSearch InnerHitBuilder.
37+
* Each InnerHits protobuf message represents ONE inner hit definition.
3838
*
39-
* @param innerHits
39+
* @param innerHits the protobuf InnerHits to convert
40+
* @return the converted OpenSearch InnerHitBuilder
4041
* @throws IOException if there's an error during parsing
4142
*/
42-
protected static InnerHitBuilder fromProto(List<InnerHits> innerHits) throws IOException {
43+
public static InnerHitBuilder fromProto(InnerHits innerHits) throws IOException {
44+
if (innerHits == null) {
45+
throw new IllegalArgumentException("InnerHits cannot be null");
46+
}
47+
4348
InnerHitBuilder innerHitBuilder = new InnerHitBuilder();
4449

45-
for (InnerHits innerHit : innerHits) {
46-
if (innerHit.hasName()) {
47-
innerHitBuilder.setName(innerHit.getName());
48-
}
49-
if (innerHit.hasIgnoreUnmapped()) {
50-
innerHitBuilder.setIgnoreUnmapped(innerHit.getIgnoreUnmapped());
51-
}
52-
if (innerHit.hasFrom()) {
53-
innerHitBuilder.setFrom(innerHit.getFrom());
54-
}
55-
if (innerHit.hasSize()) {
56-
innerHitBuilder.setSize(innerHit.getSize());
57-
}
58-
if (innerHit.hasExplain()) {
59-
innerHitBuilder.setExplain(innerHit.getExplain());
60-
}
61-
if (innerHit.hasVersion()) {
62-
innerHitBuilder.setVersion(innerHit.getVersion());
63-
}
64-
if (innerHit.hasSeqNoPrimaryTerm()) {
65-
innerHitBuilder.setSeqNoAndPrimaryTerm(innerHit.getSeqNoPrimaryTerm());
66-
}
67-
if (innerHit.hasTrackScores()) {
68-
innerHitBuilder.setTrackScores(innerHit.getTrackScores());
69-
}
70-
if (innerHit.getStoredFieldsCount() > 0) {
71-
innerHitBuilder.setStoredFieldNames(innerHit.getStoredFieldsList());
72-
}
73-
if (innerHit.getDocvalueFieldsCount() > 0) {
74-
List<FieldAndFormat> fieldAndFormatList = new ArrayList<>();
75-
for (org.opensearch.protobufs.FieldAndFormat fieldAndFormat : innerHit.getDocvalueFieldsList()) {
76-
fieldAndFormatList.add(FieldAndFormatProtoUtils.fromProto(fieldAndFormat));
77-
}
78-
innerHitBuilder.setDocValueFields(fieldAndFormatList);
79-
}
80-
if (innerHit.getFieldsCount() > 0) {
81-
List<FieldAndFormat> fieldAndFormatList = new ArrayList<>();
82-
// TODO: this is not correct, we need to use FieldAndFormatProtoUtils.fromProto() and fix the protobufs in 0.11.0
83-
for (String fieldName : innerHit.getFieldsList()) {
84-
fieldAndFormatList.add(new FieldAndFormat(fieldName, null));
85-
}
86-
innerHitBuilder.setFetchFields(fieldAndFormatList);
87-
}
88-
if (innerHit.getScriptFieldsCount() > 0) {
89-
Set<SearchSourceBuilder.ScriptField> scriptFields = new HashSet<>();
90-
for (Map.Entry<String, ScriptField> entry : innerHit.getScriptFieldsMap().entrySet()) {
91-
String name = entry.getKey();
92-
ScriptField scriptFieldProto = entry.getValue();
93-
SearchSourceBuilder.ScriptField scriptField = SearchSourceBuilderProtoUtils.ScriptFieldProtoUtils.fromProto(
94-
name,
95-
scriptFieldProto
96-
);
97-
scriptFields.add(scriptField);
98-
}
99-
innerHitBuilder.setScriptFields(scriptFields);
100-
}
101-
if (innerHit.getSortCount() > 0) {
102-
innerHitBuilder.setSorts(SortBuilderProtoUtils.fromProto(innerHit.getSortList()));
103-
}
104-
if (innerHit.hasXSource()) {
105-
innerHitBuilder.setFetchSourceContext(FetchSourceContextProtoUtils.fromProto(innerHit.getXSource()));
106-
}
107-
if (innerHit.hasHighlight()) {
108-
innerHitBuilder.setHighlightBuilder(HighlightBuilderProtoUtils.fromProto(innerHit.getHighlight()));
50+
if (innerHits.hasName()) {
51+
innerHitBuilder.setName(innerHits.getName());
52+
}
53+
if (innerHits.hasIgnoreUnmapped()) {
54+
innerHitBuilder.setIgnoreUnmapped(innerHits.getIgnoreUnmapped());
55+
}
56+
if (innerHits.hasFrom()) {
57+
innerHitBuilder.setFrom(innerHits.getFrom());
58+
}
59+
if (innerHits.hasSize()) {
60+
innerHitBuilder.setSize(innerHits.getSize());
61+
}
62+
if (innerHits.hasExplain()) {
63+
innerHitBuilder.setExplain(innerHits.getExplain());
64+
}
65+
if (innerHits.hasVersion()) {
66+
innerHitBuilder.setVersion(innerHits.getVersion());
67+
}
68+
if (innerHits.hasSeqNoPrimaryTerm()) {
69+
innerHitBuilder.setSeqNoAndPrimaryTerm(innerHits.getSeqNoPrimaryTerm());
70+
}
71+
if (innerHits.hasTrackScores()) {
72+
innerHitBuilder.setTrackScores(innerHits.getTrackScores());
73+
}
74+
if (innerHits.getStoredFieldsCount() > 0) {
75+
innerHitBuilder.setStoredFieldNames(innerHits.getStoredFieldsList());
76+
}
77+
if (innerHits.getDocvalueFieldsCount() > 0) {
78+
List<FieldAndFormat> fieldAndFormatList = new ArrayList<>();
79+
for (org.opensearch.protobufs.FieldAndFormat fieldAndFormat : innerHits.getDocvalueFieldsList()) {
80+
fieldAndFormatList.add(FieldAndFormatProtoUtils.fromProto(fieldAndFormat));
10981
}
110-
if (innerHit.hasCollapse()) {
111-
innerHitBuilder.setInnerCollapse(CollapseBuilderProtoUtils.fromProto(innerHit.getCollapse()));
82+
innerHitBuilder.setDocValueFields(fieldAndFormatList);
83+
}
84+
if (innerHits.getFieldsCount() > 0) {
85+
List<FieldAndFormat> fieldAndFormatList = new ArrayList<>();
86+
// TODO: this is not correct, we need to use FieldAndFormatProtoUtils.fromProto() and fix the protobufs in 0.11.0
87+
for (String fieldName : innerHits.getFieldsList()) {
88+
fieldAndFormatList.add(new FieldAndFormat(fieldName, null));
11289
}
90+
innerHitBuilder.setFetchFields(fieldAndFormatList);
91+
}
92+
if (innerHits.getScriptFieldsCount() > 0) {
93+
Set<SearchSourceBuilder.ScriptField> scriptFields = new HashSet<>();
94+
for (Map.Entry<String, ScriptField> entry : innerHits.getScriptFieldsMap().entrySet()) {
95+
String name = entry.getKey();
96+
ScriptField scriptFieldProto = entry.getValue();
97+
SearchSourceBuilder.ScriptField scriptField = SearchSourceBuilderProtoUtils.ScriptFieldProtoUtils.fromProto(
98+
name,
99+
scriptFieldProto
100+
);
101+
scriptFields.add(scriptField);
102+
}
103+
innerHitBuilder.setScriptFields(scriptFields);
104+
}
105+
if (innerHits.getSortCount() > 0) {
106+
innerHitBuilder.setSorts(SortBuilderProtoUtils.fromProto(innerHits.getSortList()));
107+
}
108+
if (innerHits.hasXSource()) {
109+
innerHitBuilder.setFetchSourceContext(FetchSourceContextProtoUtils.fromProto(innerHits.getXSource()));
110+
}
111+
if (innerHits.hasHighlight()) {
112+
innerHitBuilder.setHighlightBuilder(HighlightBuilderProtoUtils.fromProto(innerHits.getHighlight()));
113+
}
114+
if (innerHits.hasCollapse()) {
115+
innerHitBuilder.setInnerCollapse(CollapseBuilderProtoUtils.fromProto(innerHits.getCollapse()));
113116
}
117+
114118
return innerHitBuilder;
115119
}
116120

121+
/**
122+
* Converts a list of protobuf InnerHits to a list of OpenSearch InnerHitBuilder objects.
123+
* Each InnerHits protobuf message represents ONE inner hit definition.
124+
*
125+
* @param innerHitsList the list of protobuf InnerHits to convert
126+
* @return the list of converted OpenSearch InnerHitBuilder objects
127+
* @throws IOException if there's an error during parsing
128+
*/
129+
public static List<InnerHitBuilder> fromProto(List<InnerHits> innerHitsList) throws IOException {
130+
if (innerHitsList == null) {
131+
throw new IllegalArgumentException("InnerHits list cannot be null");
132+
}
133+
134+
List<InnerHitBuilder> innerHitBuilders = new ArrayList<>();
135+
for (InnerHits innerHits : innerHitsList) {
136+
innerHitBuilders.add(fromProto(innerHits));
137+
}
138+
return innerHitBuilders;
139+
}
140+
117141
}

0 commit comments

Comments
 (0)