Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add all-active ingestion as docrep equivalent in pull-based ingestion ([#19316](https://github.com/opensearch-project/OpenSearch/pull/19316))
- Adding logic for histogram aggregation using skiplist ([#19130](https://github.com/opensearch-project/OpenSearch/pull/19130))
- Add skip_list param for date, scaled float and token count fields ([#19142](https://github.com/opensearch-project/OpenSearch/pull/19142))
- Implement GRPC Ids, Range, and Terms Set queries ([#19448](https://github.com/opensearch-project/OpenSearch/pull/19448))

### Changed
- Refactor `if-else` chains to use `Java 17 pattern matching switch expressions`(([#18965](https://github.com/opensearch-project/OpenSearch/pull/18965))
Expand All @@ -48,6 +49,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
1 change: 0 additions & 1 deletion modules/transport-grpc/licenses/protobufs-0.13.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions modules/transport-grpc/licenses/protobufs-0.18.0.jar.sha1
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
@@ -0,0 +1,41 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.transport.grpc.proto.request.search.query;

import org.opensearch.index.query.QueryBuilder;
import org.opensearch.protobufs.QueryContainer;
import org.opensearch.transport.grpc.spi.QueryBuilderProtoConverter;

/**
* Converter for Ids queries.
* This class implements the QueryBuilderProtoConverter interface to provide Ids query support
* for the gRPC transport module.
*/
public class IdsQueryBuilderProtoConverter implements QueryBuilderProtoConverter {

/**
* Constructs a new IdsQueryBuilderProtoConverter.
*/
public IdsQueryBuilderProtoConverter() {
// Default constructor
}

@Override
public QueryContainer.QueryContainerCase getHandledQueryCase() {
return QueryContainer.QueryContainerCase.IDS;
}

@Override
public QueryBuilder fromProto(QueryContainer queryContainer) {
if (queryContainer == null || !queryContainer.hasIds()) {
throw new IllegalArgumentException("QueryContainer does not contain an Ids query");
}

return IdsQueryBuilderProtoUtils.fromProto(queryContainer.getIds());
}
}
Loading
Loading