diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a72b3edccd70..1ace7428d1015 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,10 +46,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Bump `actions/upload-artifact` from 5 to 6 ([#20333](https://github.com/opensearch-project/OpenSearch/pull/20333)) - Bump `com.google.http-client:google-http-client-appengine` from 2.0.2 to 2.0.3 ([#20332](https://github.com/opensearch-project/OpenSearch/pull/20332)) - Bump `jackson` from 2.18.1 to 2.20.1 ([#20343](https://github.com/opensearch-project/OpenSearch/pull/20343)) +- Bump `opensearch-protobufs` from 0.24.0 to 1.0.0 and update transport-grpc module compatibility ([#20335](https://github.com/opensearch-project/OpenSearch/pull/20335)) ### Removed - Remove identity-shiro from plugins folder ([#20305](https://github.com/opensearch-project/OpenSearch/pull/20305)) [Unreleased 3.x]: https://github.com/opensearch-project/OpenSearch/compare/3.4...main - diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5ed18042bb1bf..b24bfe49312a7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,7 +24,7 @@ kotlin = "1.7.10" antlr4 = "4.13.1" guava = "33.2.1-jre" gson = "2.13.2" -opensearchprotobufs = "0.24.0" +opensearchprotobufs = "1.0.0" protobuf = "3.25.8" jakarta_annotation = "1.3.5" google_http_client = "1.44.1" diff --git a/modules/transport-grpc/licenses/protobufs-0.24.0.jar.sha1 b/modules/transport-grpc/licenses/protobufs-0.24.0.jar.sha1 deleted file mode 100644 index 498201f42b019..0000000000000 --- a/modules/transport-grpc/licenses/protobufs-0.24.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -4330dd089f853e345aa137708490aec841ffadc0 \ No newline at end of file diff --git a/modules/transport-grpc/licenses/protobufs-1.0.0.jar.sha1 b/modules/transport-grpc/licenses/protobufs-1.0.0.jar.sha1 new file mode 100644 index 0000000000000..8daf74b220d1b --- /dev/null +++ b/modules/transport-grpc/licenses/protobufs-1.0.0.jar.sha1 @@ -0,0 +1 @@ +495727dc62f515bd34e37dcdda976026b0aaf33a \ No newline at end of file diff --git a/modules/transport-grpc/spi/licenses/protobufs-0.24.0.jar.sha1 b/modules/transport-grpc/spi/licenses/protobufs-0.24.0.jar.sha1 deleted file mode 100644 index 498201f42b019..0000000000000 --- a/modules/transport-grpc/spi/licenses/protobufs-0.24.0.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -4330dd089f853e345aa137708490aec841ffadc0 \ No newline at end of file diff --git a/modules/transport-grpc/spi/licenses/protobufs-1.0.0.jar.sha1 b/modules/transport-grpc/spi/licenses/protobufs-1.0.0.jar.sha1 new file mode 100644 index 0000000000000..8daf74b220d1b --- /dev/null +++ b/modules/transport-grpc/spi/licenses/protobufs-1.0.0.jar.sha1 @@ -0,0 +1 @@ +495727dc62f515bd34e37dcdda976026b0aaf33a \ No newline at end of file diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java index 51f19e1139e87..ea098587584c8 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java @@ -308,11 +308,14 @@ private static HighlightBuilder.BoundaryScannerType parseBoundaryScanner(Boundar */ private static void applyTagsSchemaToField(HighlightBuilder.Field fieldBuilder, HighlighterTagsSchema tagsSchema) { switch (tagsSchema) { - // TODO add HIGHLIGHTER_TAGS_SCHEMA_DEFAULT once new protobufs are published after spec fix case HIGHLIGHTER_TAGS_SCHEMA_STYLED: fieldBuilder.preTags(HighlightBuilder.DEFAULT_STYLED_PRE_TAG); fieldBuilder.postTags(HighlightBuilder.DEFAULT_STYLED_POST_TAGS); break; + case HIGHLIGHTER_TAGS_SCHEMA_DEFAULT: + fieldBuilder.preTags(HighlightBuilder.DEFAULT_PRE_TAGS); + fieldBuilder.postTags(HighlightBuilder.DEFAULT_POST_TAGS); + break; default: throw new IllegalArgumentException("Unknown tags schema: " + tagsSchema); } diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/SearchSourceBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/SearchSourceBuilderProtoUtils.java index ce2e8bf5a4afe..daf02cea61cde 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/SearchSourceBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/SearchSourceBuilderProtoUtils.java @@ -152,20 +152,24 @@ private static void parseNonQueryFields( } } - // TODO support aggregations + // Aggregations field was removed in protobufs 1.0.0 + // TODO: Support aggregations when they are re-added to the proto + /* if (protoRequest.getAggregationsCount() > 0) { throw new UnsupportedOperationException("aggregations param is not supported yet"); } - + */ if (protoRequest.hasHighlight()) { searchSourceBuilder.highlighter(HighlightBuilderProtoUtils.fromProto(protoRequest.getHighlight(), registry)); } - // TODO support suggest + // TODO support suggest once added back to the protos + /* if (protoRequest.hasSuggest()) { throw new UnsupportedOperationException("suggest param is not supported yet"); // searchSourceBuilder.suggest(SuggestBuilderProtoUtils.fromProto(protoRequest.getSuggest())); } + */ if (protoRequest.getRescoreCount() > 0) { for (Rescore rescore : protoRequest.getRescoreList()) { searchSourceBuilder.addRescorer(RescorerBuilderProtoUtils.parseFromProto(rescore)); diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoUtils.java index a104c16193f9e..ed761a990222d 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoUtils.java @@ -11,9 +11,7 @@ import org.opensearch.index.query.AbstractQueryBuilder; import org.opensearch.index.query.FuzzyQueryBuilder; import org.opensearch.protobufs.FuzzyQuery; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.transport.grpc.proto.response.common.FieldValueProtoUtils; -import org.opensearch.transport.grpc.util.ProtobufEnumUtils; /** * Utility class for converting FuzzyQuery Protocol Buffers to OpenSearch objects. @@ -74,10 +72,7 @@ static FuzzyQueryBuilder fromProto(FuzzyQuery fuzzyQueryProto) { } if (fuzzyQueryProto.hasRewrite()) { - MultiTermQueryRewrite rewriteEnum = fuzzyQueryProto.getRewrite(); - if (rewriteEnum != MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) { - rewrite = ProtobufEnumUtils.convertToString(rewriteEnum); - } + rewrite = fuzzyQueryProto.getRewrite(); } if (fuzzyQueryProto.hasXName()) { diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MatchBoolPrefixQueryBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MatchBoolPrefixQueryBuilderProtoUtils.java index e02df53fd6ffe..b419d4882af67 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MatchBoolPrefixQueryBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MatchBoolPrefixQueryBuilderProtoUtils.java @@ -13,9 +13,7 @@ import org.opensearch.index.query.MatchBoolPrefixQueryBuilder; import org.opensearch.index.query.Operator; import org.opensearch.protobufs.MatchBoolPrefixQuery; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.transport.grpc.proto.request.search.OperatorProtoUtils; -import org.opensearch.transport.grpc.util.ProtobufEnumUtils; /** * Utility class for converting MatchBoolPrefixQuery Protocol Buffers to OpenSearch objects. @@ -93,10 +91,7 @@ static MatchBoolPrefixQueryBuilder fromProto(MatchBoolPrefixQuery matchBoolPrefi } if (matchBoolPrefixQueryProto.hasFuzzyRewrite()) { - MultiTermQueryRewrite rewriteEnum = matchBoolPrefixQueryProto.getFuzzyRewrite(); - if (rewriteEnum != MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) { - fuzzyRewrite = ProtobufEnumUtils.convertToString(rewriteEnum); - } + fuzzyRewrite = matchBoolPrefixQueryProto.getFuzzyRewrite(); } if (matchBoolPrefixQueryProto.hasBoost()) { diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MatchQueryBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MatchQueryBuilderProtoUtils.java index ea792c29e3dd0..946b5c5e3ff1b 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MatchQueryBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MatchQueryBuilderProtoUtils.java @@ -13,11 +13,9 @@ import org.opensearch.index.query.MatchQueryBuilder; import org.opensearch.index.query.Operator; import org.opensearch.index.search.MatchQuery; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.protobufs.ZeroTermsQuery; import org.opensearch.transport.grpc.proto.request.search.OperatorProtoUtils; import org.opensearch.transport.grpc.proto.response.common.FieldValueProtoUtils; -import org.opensearch.transport.grpc.util.ProtobufEnumUtils; /** * Utility class for converting MatchQuery Protocol Buffers to OpenSearch objects. @@ -101,10 +99,7 @@ static MatchQueryBuilder fromProto(org.opensearch.protobufs.MatchQuery matchQuer } if (matchQueryProto.hasFuzzyRewrite()) { - MultiTermQueryRewrite rewriteEnum = matchQueryProto.getFuzzyRewrite(); - if (rewriteEnum != MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) { - fuzzyRewrite = ProtobufEnumUtils.convertToString(rewriteEnum); - } + fuzzyRewrite = matchQueryProto.getFuzzyRewrite(); } if (matchQueryProto.hasFuzzyTranspositions()) { diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MultiMatchQueryBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MultiMatchQueryBuilderProtoUtils.java index 6b5195468364c..3dcc6605b205a 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MultiMatchQueryBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/MultiMatchQueryBuilderProtoUtils.java @@ -14,7 +14,6 @@ import org.opensearch.index.search.MatchQuery; import org.opensearch.protobufs.MultiMatchQuery; import org.opensearch.transport.grpc.proto.request.search.OperatorProtoUtils; -import org.opensearch.transport.grpc.util.ProtobufEnumUtils; import java.util.HashMap; import java.util.Map; @@ -134,10 +133,8 @@ static MultiMatchQueryBuilder fromProto(MultiMatchQuery multiMatchQueryProto) { } } - if (multiMatchQueryProto.hasFuzzyRewrite() - && multiMatchQueryProto - .getFuzzyRewrite() != org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) { - fuzzyRewrite = ProtobufEnumUtils.convertToString(multiMatchQueryProto.getFuzzyRewrite()); + if (multiMatchQueryProto.hasFuzzyRewrite()) { + fuzzyRewrite = multiMatchQueryProto.getFuzzyRewrite(); } if (multiMatchQueryProto.hasTieBreaker()) { diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoUtils.java index f5a3e575a2c15..0b30ee588d4e8 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoUtils.java @@ -9,9 +9,7 @@ import org.opensearch.index.query.AbstractQueryBuilder; import org.opensearch.index.query.PrefixQueryBuilder; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.protobufs.PrefixQuery; -import org.opensearch.transport.grpc.util.ProtobufEnumUtils; /** * Utility class for converting PrefixQuery Protocol Buffers to OpenSearch objects. @@ -52,10 +50,7 @@ static PrefixQueryBuilder fromProto(PrefixQuery prefixQueryProto) { } if (prefixQueryProto.hasRewrite()) { - MultiTermQueryRewrite rewriteEnum = prefixQueryProto.getRewrite(); - if (rewriteEnum != MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) { - rewrite = ProtobufEnumUtils.convertToString(rewriteEnum); - } + rewrite = prefixQueryProto.getRewrite(); } if (prefixQueryProto.hasCaseInsensitive()) { caseInsensitive = prefixQueryProto.getCaseInsensitive(); diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/RegexpQueryBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/RegexpQueryBuilderProtoUtils.java index 56c5f7a5f4e72..241fc906f30d7 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/RegexpQueryBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/RegexpQueryBuilderProtoUtils.java @@ -10,9 +10,7 @@ import org.opensearch.core.xcontent.XContentParser; import org.opensearch.index.query.AbstractQueryBuilder; import org.opensearch.index.query.RegexpQueryBuilder; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.protobufs.RegexpQuery; -import org.opensearch.transport.grpc.util.ProtobufEnumUtils; /** * Utility class for converting RegexpQuery Protocol Buffers to OpenSearch objects. @@ -51,11 +49,7 @@ static RegexpQueryBuilder fromProto(RegexpQuery regexpQueryProto) { } if (regexpQueryProto.hasRewrite()) { - MultiTermQueryRewrite rewriteEnum = regexpQueryProto.getRewrite(); - // Skip setting rewrite method if it's UNSPECIFIED - if (rewriteEnum != MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) { - rewrite = ProtobufEnumUtils.convertToString(rewriteEnum); - } + rewrite = regexpQueryProto.getRewrite(); } if (regexpQueryProto.hasFlags()) { diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsLookupProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsLookupProtoUtils.java index 420fe4704550f..606a75cf92e29 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsLookupProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsLookupProtoUtils.java @@ -9,7 +9,6 @@ import org.opensearch.core.xcontent.XContentParser; import org.opensearch.indices.TermsLookup; -import org.opensearch.protobufs.TermsLookupField; /** * Utility class for converting TermsLookup Protocol Buffers to OpenSearch objects. @@ -23,26 +22,26 @@ private TermsLookupProtoUtils() { } /** - * Converts a Protocol Buffer TermsLookupField to an OpenSearch TermsLookup object. + * Converts a Protocol Buffer TermsLookup to an OpenSearch TermsLookup object. * Similar to {@link TermsLookup#parseTermsLookup(XContentParser)} * - * @param termsLookupFieldProto The Protocol Buffer TermsLookupField object containing index, id, path, and optional routing/store values + * @param termsLookupProto The Protocol Buffer TermsLookup object containing index, id, path, and optional routing/store values * @return A configured TermsLookup instance with the appropriate settings */ - protected static TermsLookup parseTermsLookup(TermsLookupField termsLookupFieldProto) { + protected static TermsLookup parseTermsLookup(org.opensearch.protobufs.TermsLookup termsLookupProto) { - String index = termsLookupFieldProto.getIndex(); - String id = termsLookupFieldProto.getId(); - String path = termsLookupFieldProto.getPath(); + String index = termsLookupProto.getIndex(); + String id = termsLookupProto.getId(); + String path = termsLookupProto.getPath(); TermsLookup termsLookup = new TermsLookup(index, id, path); - if (termsLookupFieldProto.hasRouting()) { - termsLookup.routing(termsLookupFieldProto.getRouting()); + if (termsLookupProto.hasRouting()) { + termsLookup.routing(termsLookupProto.getRouting()); } - if (termsLookupFieldProto.hasStore()) { - termsLookup.store(termsLookupFieldProto.getStore()); + if (termsLookupProto.hasStore()) { + termsLookup.store(termsLookupProto.getStore()); } return termsLookup; diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtils.java index c751a5586c68a..8efe4142c7557 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtils.java @@ -13,7 +13,6 @@ import org.opensearch.index.query.TermsQueryBuilder; import org.opensearch.indices.TermsLookup; import org.opensearch.protobufs.TermsQueryField; -import org.opensearch.protobufs.ValueType; import org.opensearch.transport.grpc.proto.response.common.FieldValueProtoUtils; import java.util.ArrayList; @@ -178,27 +177,6 @@ static TermsQueryBuilder fromProto( return termsQueryBuilder.valueType(valueType); } - /** - * Parses a protobuf ScriptLanguage to a String representation - * - * See {@link org.opensearch.index.query.TermsQueryBuilder.ValueType#fromString(String)} } - * * - * @param valueType the Protocol Buffer ValueType to convert - * @return the string representation of the script language - * @throws UnsupportedOperationException if no language was specified - */ - public static TermsQueryBuilder.ValueType parseValueType(ValueType valueType) { - switch (valueType) { - case VALUE_TYPE_BITMAP: - return TermsQueryBuilder.ValueType.BITMAP; - case VALUE_TYPE_DEFAULT: - return TermsQueryBuilder.ValueType.DEFAULT; - case VALUE_TYPE_UNSPECIFIED: - default: - return TermsQueryBuilder.ValueType.DEFAULT; - } - } - /** * Parses a protobuf TermsQueryValueType to OpenSearch TermsQueryBuilder.ValueType * @param valueTypeProto the Protocol Buffer TermsQueryValueType to convert diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/WildcardQueryBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/WildcardQueryBuilderProtoUtils.java index 17a851c840b92..48cc541761698 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/WildcardQueryBuilderProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/WildcardQueryBuilderProtoUtils.java @@ -10,9 +10,7 @@ import org.opensearch.core.xcontent.XContentParser; import org.opensearch.index.query.AbstractQueryBuilder; import org.opensearch.index.query.WildcardQueryBuilder; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.protobufs.WildcardQuery; -import org.opensearch.transport.grpc.util.ProtobufEnumUtils; /** * Utility class for converting wildcardQueryProto Protocol Buffers to OpenSearch objects. @@ -58,11 +56,7 @@ static WildcardQueryBuilder fromProto(WildcardQuery wildcardQueryProto) { } if (wildcardQueryProto.hasRewrite()) { - MultiTermQueryRewrite rewriteEnum = wildcardQueryProto.getRewrite(); - // Skip setting rewrite method if it's UNSPECIFIED - if (rewriteEnum != MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) { - rewrite = ProtobufEnumUtils.convertToString(rewriteEnum); - } + rewrite = wildcardQueryProto.getRewrite(); } if (wildcardQueryProto.hasCaseInsensitive()) { diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/suggest/SuggestBuilderProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/suggest/SuggestBuilderProtoUtils.java deleted file mode 100644 index e74da6862abf1..0000000000000 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/suggest/SuggestBuilderProtoUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.suggest; - -import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.protobufs.Suggester; -import org.opensearch.search.suggest.SuggestBuilder; - -/** - * Utility class for converting Highlight Protocol Buffers to objects - * - */ -public class SuggestBuilderProtoUtils { - - private SuggestBuilderProtoUtils() { - // Utility class, no instances - } - - /** - * Similar to {@link SuggestBuilder#fromXContent(XContentParser)} - * - * @param suggesterProto - */ - - public static SuggestBuilder fromProto(Suggester suggesterProto) { - SuggestBuilder suggestBuilder = new SuggestBuilder(); - - // TODO populate suggestBuilder - - return suggestBuilder; - } -} diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/common/FieldValueProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/common/FieldValueProtoUtils.java index 571e33ab8891c..d5cf9c07fc453 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/common/FieldValueProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/common/FieldValueProtoUtils.java @@ -120,6 +120,8 @@ public static Object fromProto(FieldValue fieldValue, boolean convertStringsToBy return generalNumber.getFloatValue(); case DOUBLE_VALUE: return generalNumber.getDoubleValue(); + case UINT64_VALUE: + return generalNumber.getUint64Value(); default: throw new IllegalArgumentException("Unsupported general number type: " + generalNumber.getValueCase()); } diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java index 757de75993004..a0db60167eff1 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/exceptions/opensearchexception/OpenSearchExceptionProtoUtils.java @@ -19,7 +19,6 @@ import org.opensearch.protobufs.ErrorCause; import org.opensearch.protobufs.ObjectMap; import org.opensearch.protobufs.StringArray; -import org.opensearch.protobufs.StringOrStringArray; import org.opensearch.script.ScriptException; import org.opensearch.search.SearchParseException; import org.opensearch.search.aggregations.MultiBucketConsumerService; @@ -158,8 +157,10 @@ public static ErrorCause innerToProto( if (headers.isEmpty() == false) { for (Map.Entry> entry : headers.entrySet()) { - Map.Entry protoEntry = headerToProto(entry.getKey(), entry.getValue()); - errorCauseBuilder.putHeader(protoEntry.getKey(), protoEntry.getValue()); + StringArray headerArray = headerToProto(entry.getKey(), entry.getValue()); + if (headerArray != null) { + errorCauseBuilder.putHeader(entry.getKey(), headerArray); + } } } @@ -178,32 +179,21 @@ public static ErrorCause innerToProto( } /** - * Converts a single entry of a {@code Map>} into a protobuf {@code } + * Converts a list of header values into a protobuf StringArray. * Similar to {@link OpenSearchException#headerToXContent(XContentBuilder, String, List)} * - * @param key The key of the header entry + * @param key The key of the header entry (unused but kept for API compatibility) * @param values The list of values for the header entry - * @return A map entry containing the key and its corresponding StringOrStringArray value, or null if values is null or empty + * @return A StringArray containing the values, or null if values is null or empty * @throws IOException if there's an error during conversion */ - public static Map.Entry headerToProto(String key, List values) throws IOException { + public static StringArray headerToProto(String key, List values) throws IOException { if (values != null && values.isEmpty() == false) { - if (values.size() == 1) { - return new AbstractMap.SimpleEntry( - key, - StringOrStringArray.newBuilder().setString(values.get(0)).build() - ); - } else { - StringArray.Builder stringArrayBuilder = StringArray.newBuilder(); - for (String val : values) { - stringArrayBuilder.addStringArray(val); - } - StringOrStringArray stringOrStringArray = StringOrStringArray.newBuilder() - .setStringArray(stringArrayBuilder.build()) - .build(); - - return new AbstractMap.SimpleEntry(key, stringOrStringArray); + StringArray.Builder stringArrayBuilder = StringArray.newBuilder(); + for (String val : values) { + stringArrayBuilder.addStringArray(val); } + return stringArrayBuilder.build(); } return null; } diff --git a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseSectionsProtoUtils.java b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseSectionsProtoUtils.java index a3464ce16d395..7153dcc7c5a8d 100644 --- a/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseSectionsProtoUtils.java +++ b/modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseSectionsProtoUtils.java @@ -9,10 +9,11 @@ import org.opensearch.action.search.SearchResponse; import org.opensearch.action.search.SearchResponseSections; -import org.opensearch.core.xcontent.ToXContent; -import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.transport.grpc.proto.response.common.ObjectMapProtoUtils; import java.io.IOException; +import java.util.List; +import java.util.Locale; /** * Utility class for converting SearchResponse objects to Protocol Buffers. @@ -39,6 +40,36 @@ protected static void toProto(org.opensearch.protobufs.SearchResponse.Builder bu SearchHitsProtoUtils.toProto(response.getHits(), hitsBuilder); builder.setHits(hitsBuilder.build()); + // Convert processor results + List processorResults = response.getInternalResponse() + .getProcessorResult(); + if (processorResults != null && !processorResults.isEmpty()) { + for (org.opensearch.search.pipeline.ProcessorExecutionDetail detail : processorResults) { + org.opensearch.protobufs.ProcessorExecutionDetail.Builder detailBuilder = org.opensearch.protobufs.ProcessorExecutionDetail + .newBuilder(); + if (detail.getProcessorName() != null) { + detailBuilder.setProcessorName(detail.getProcessorName()); + } + detailBuilder.setDurationMillis(detail.getDurationMillis()); + if (detail.getInputData() != null) { + detailBuilder.setInputData(ObjectMapProtoUtils.toProto(detail.getInputData()).getObjectMap()); + } + if (detail.getOutputData() != null) { + detailBuilder.setOutputData(ObjectMapProtoUtils.toProto(detail.getOutputData()).getObjectMap()); + } + if (detail.getStatus() != null) { + detailBuilder.setStatus(detail.getStatus().name().toLowerCase(Locale.ROOT)); + } + if (detail.getErrorMessage() != null) { + detailBuilder.setError(detail.getErrorMessage()); + } + if (detail.getTag() != null) { + detailBuilder.setTag(detail.getTag()); + } + builder.addProcessorResults(detailBuilder.build()); + } + } + // Check for unsupported features checkUnsupportedFeatures(response); } diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java index 2841fa19ebaeb..a142421a2603e 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java @@ -446,7 +446,7 @@ public void testFromProto_WithFieldRequireFieldMatch() { assertFalse(field.requireFieldMatch()); } - public void testFromProto_WithFieldTagsSchema() { + public void testFromProto_WithFieldTagsSchemaStyled() { HighlightField fieldProto = HighlightField.newBuilder().setTagsSchema(HighlighterTagsSchema.HIGHLIGHTER_TAGS_SCHEMA_STYLED).build(); Highlight highlightProto = Highlight.newBuilder().putFields("title", fieldProto).build(); @@ -459,6 +459,37 @@ public void testFromProto_WithFieldTagsSchema() { // The tags schema should have been applied - verify the field was created HighlightBuilder.Field field = fields.get(0); assertEquals("title", field.name()); + // Verify styled tags were applied + String[] preTags = field.preTags(); + assertNotNull(preTags); + assertArrayEquals(HighlightBuilder.DEFAULT_STYLED_PRE_TAG, preTags); + String[] postTags = field.postTags(); + assertNotNull(postTags); + assertArrayEquals(HighlightBuilder.DEFAULT_STYLED_POST_TAGS, postTags); + } + + public void testFromProto_WithFieldTagsSchemaDefault() { + HighlightField fieldProto = HighlightField.newBuilder() + .setTagsSchema(HighlighterTagsSchema.HIGHLIGHTER_TAGS_SCHEMA_DEFAULT) + .build(); + + Highlight highlightProto = Highlight.newBuilder().putFields("title", fieldProto).build(); + HighlightBuilder result = HighlightBuilderProtoUtils.fromProto(highlightProto, registry); + + assertNotNull(result); + List fields = result.fields(); + assertEquals(1, fields.size()); + + // The tags schema should have been applied - verify the field was created + HighlightBuilder.Field field = fields.get(0); + assertEquals("title", field.name()); + // Verify default tags were applied + String[] preTags = field.preTags(); + assertNotNull(preTags); + assertArrayEquals(HighlightBuilder.DEFAULT_PRE_TAGS, preTags); + String[] postTags = field.postTags(); + assertNotNull(postTags); + assertArrayEquals(HighlightBuilder.DEFAULT_POST_TAGS, postTags); } public void testFromProto_WithFieldForceSource() { diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/SearchSourceBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/SearchSourceBuilderProtoUtilsTests.java index d10a17e89dce7..ac305af038d86 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/SearchSourceBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/SearchSourceBuilderProtoUtilsTests.java @@ -611,24 +611,6 @@ public void testParseProtoWithExtThrowsUnsupportedOperationException() throws IO assertTrue("Exception message should mention ext param", exception.getMessage().contains("ext param is not supported yet")); } - public void testParseProtoWithAggregationsThrowsUnsupportedOperationException() throws IOException { - // Create a protobuf SearchRequestBody with aggregations - SearchRequestBody protoRequest = SearchRequestBody.newBuilder() - .putAggregations("test_agg", org.opensearch.protobufs.AggregationContainer.newBuilder().build()) - .build(); - - // Create a SearchSourceBuilder to populate - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - - // Call the method under test, should throw UnsupportedOperationException - UnsupportedOperationException exception = expectThrows( - UnsupportedOperationException.class, - () -> SearchSourceBuilderProtoUtils.parseProto(searchSourceBuilder, protoRequest, queryUtils) - ); - - assertEquals("aggregations param is not supported yet", exception.getMessage()); - } - public void testScriptFieldProtoUtilsFromProto() throws IOException { // Create a protobuf ScriptField ScriptField scriptFieldProto = ScriptField.newBuilder() @@ -744,18 +726,15 @@ public void testParseProtoWithSort() throws IOException { } public void testParseProtoWithSuggest() throws IOException { - SearchRequestBody protoRequest = SearchRequestBody.newBuilder() - .setSuggest(org.opensearch.protobufs.Suggester.newBuilder().setText("opensearch").build()) - .build(); + // Suggester field was removed from SearchRequestBody in protobufs 1.0.0 + // Suggest functionality is now handled via SearchRequest URL parameters (suggest_field, suggest_text, etc.) + // This test is no longer applicable as the field doesn't exist + SearchRequestBody protoRequest = SearchRequestBody.newBuilder().build(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - // suggest is not yet implemented, should throw UnsupportedOperationException - UnsupportedOperationException exception = expectThrows( - UnsupportedOperationException.class, - () -> SearchSourceBuilderProtoUtils.parseProto(searchSourceBuilder, protoRequest, queryUtils) - ); - assertEquals("suggest param is not supported yet", exception.getMessage()); + // Should not throw exception as suggest field no longer exists + SearchSourceBuilderProtoUtils.parseProto(searchSourceBuilder, protoRequest, queryUtils); } public void testParseProtoWithXSourceIncludes() throws IOException { diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoConverterTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoConverterTests.java index 95acf4e667cc4..6cbecd2141626 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoConverterTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoConverterTests.java @@ -39,7 +39,7 @@ public void testFromProto() { .setPrefixLength(2) .setMaxExpansions(100) .setTranspositions(true) - .setRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setRewrite("constant_score") .build(); QueryContainer queryContainer = QueryContainer.newBuilder().setFuzzy(fuzzyQuery).build(); diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoUtilsTests.java index a6570acc33d75..30638ccbd0544 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/FuzzyQueryBuilderProtoUtilsTests.java @@ -11,7 +11,6 @@ import org.opensearch.common.unit.Fuzziness; import org.opensearch.index.query.FuzzyQueryBuilder; import org.opensearch.protobufs.FieldValue; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.test.OpenSearchTestCase; public class FuzzyQueryBuilderProtoUtilsTests extends OpenSearchTestCase { @@ -46,7 +45,7 @@ public void testFromProtoWithAllParameters() { .setPrefixLength(2) .setMaxExpansions(100) .setTranspositions(false) - .setRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setRewrite("constant_score") .setBoost(1.5f) .setXName("test_query") .build(); diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MatchBoolPrefixQueryBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MatchBoolPrefixQueryBuilderProtoUtilsTests.java index 40f453449fda8..bc7884fd5ceab 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MatchBoolPrefixQueryBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MatchBoolPrefixQueryBuilderProtoUtilsTests.java @@ -13,7 +13,6 @@ import org.opensearch.index.query.Operator; import org.opensearch.protobufs.MatchBoolPrefixQuery; import org.opensearch.protobufs.MinimumShouldMatch; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.test.OpenSearchTestCase; public class MatchBoolPrefixQueryBuilderProtoUtilsTests extends OpenSearchTestCase { @@ -185,22 +184,13 @@ public void testFromProtoWithFuzzyRewrite() { MatchBoolPrefixQuery queryWithRewrite = MatchBoolPrefixQuery.newBuilder() .setField("message") .setQuery("test") - .setFuzzyRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setFuzzyRewrite("constant_score") .build(); MatchBoolPrefixQueryBuilder builderWithRewrite = MatchBoolPrefixQueryBuilderProtoUtils.fromProto(queryWithRewrite); assertNotNull("Builder should not be null (CONSTANT_SCORE)", builderWithRewrite); assertNotNull("Fuzzy rewrite should not be null (CONSTANT_SCORE)", builderWithRewrite.fuzzyRewrite()); assertEquals("Fuzzy rewrite should match (CONSTANT_SCORE)", "constant_score", builderWithRewrite.fuzzyRewrite()); - // Test 3: Fuzzy rewrite with UNSPECIFIED value - MatchBoolPrefixQuery queryUnspecified = MatchBoolPrefixQuery.newBuilder() - .setField("message") - .setQuery("test") - .setFuzzyRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) - .build(); - MatchBoolPrefixQueryBuilder builderUnspecified = MatchBoolPrefixQueryBuilderProtoUtils.fromProto(queryUnspecified); - assertNotNull("Builder should not be null (UNSPECIFIED)", builderUnspecified); - assertNull("Fuzzy rewrite should be null (UNSPECIFIED)", builderUnspecified.fuzzyRewrite()); } } diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MatchQueryBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MatchQueryBuilderProtoUtilsTests.java index 936c8196f9f24..e2edb885733d9 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MatchQueryBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MatchQueryBuilderProtoUtilsTests.java @@ -184,22 +184,13 @@ public void testFromProtoWithFuzzyRewrite() { org.opensearch.protobufs.MatchQuery queryWithRewrite = org.opensearch.protobufs.MatchQuery.newBuilder() .setField("message") .setQuery(queryValue) - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setFuzzyRewrite("constant_score") .build(); MatchQueryBuilder builderWithRewrite = MatchQueryBuilderProtoUtils.fromProto(queryWithRewrite); assertNotNull("Builder should not be null (CONSTANT_SCORE)", builderWithRewrite); assertNotNull("Fuzzy rewrite should not be null (CONSTANT_SCORE)", builderWithRewrite.fuzzyRewrite()); assertEquals("Fuzzy rewrite should match (CONSTANT_SCORE)", "constant_score", builderWithRewrite.fuzzyRewrite()); - // Test 2: FuzzyRewrite with UNSPECIFIED value - org.opensearch.protobufs.MatchQuery queryUnspecified = org.opensearch.protobufs.MatchQuery.newBuilder() - .setField("message") - .setQuery(queryValue) - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) - .build(); - MatchQueryBuilder builderUnspecified = MatchQueryBuilderProtoUtils.fromProto(queryUnspecified); - assertNotNull("Builder should not be null (UNSPECIFIED)", builderUnspecified); - assertNull("Fuzzy rewrite should be null (UNSPECIFIED)", builderUnspecified.fuzzyRewrite()); } public void testFromProtoWithZeroTermsQueryAll() { diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MultiMatchQueryBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MultiMatchQueryBuilderProtoUtilsTests.java index 8835de4515a01..d17a7317874f2 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MultiMatchQueryBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/MultiMatchQueryBuilderProtoUtilsTests.java @@ -73,7 +73,7 @@ public void testFromProtoWithAllFields() { .setMaxExpansions(10) .setOperator(org.opensearch.protobufs.Operator.OPERATOR_AND) .setMinimumShouldMatch(MinimumShouldMatch.newBuilder().setString("2").build()) - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setFuzzyRewrite("constant_score") .setTieBreaker(0.5f) .setLenient(true) .setZeroTermsQuery(ZeroTermsQuery.ZERO_TERMS_QUERY_ALL) @@ -264,7 +264,7 @@ public void testFromProtoMatchesFromXContent() throws IOException { .setMaxExpansions(10) .setOperator(org.opensearch.protobufs.Operator.OPERATOR_AND) .setMinimumShouldMatch(MinimumShouldMatch.newBuilder().setString("2").build()) - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setFuzzyRewrite("constant_score") .setTieBreaker(0.5f) .setLenient(true) .setZeroTermsQuery(ZeroTermsQuery.ZERO_TERMS_QUERY_ALL) @@ -428,63 +428,49 @@ public void testFromProtoWithFuzziness() { assertNull("Fuzziness should be null (EMPTY)", builderEmpty.fuzziness()); } - public void testFromProtoWithFuzzyRewriteUnspecified() { - // Test that UNSPECIFIED fuzzyRewrite is treated as null - MultiMatchQuery proto = MultiMatchQuery.newBuilder() - .setQuery("test query") - .addFields("field1") - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) - .build(); - - MultiMatchQueryBuilder builder = fromProto(proto); - - // Verify fuzzyRewrite is null when UNSPECIFIED - assertNull("FuzzyRewrite should be null for UNSPECIFIED", builder.fuzzyRewrite()); - } - public void testFromProtoWithAllFuzzyRewriteValues() { // Test all MultiTermQueryRewrite enum values MultiMatchQuery protoConstantScore = MultiMatchQuery.newBuilder() .setQuery("test") .addFields("field1") - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setFuzzyRewrite("constant_score") .build(); assertEquals("constant_score", fromProto(protoConstantScore).fuzzyRewrite()); MultiMatchQuery protoConstantScoreBoolean = MultiMatchQuery.newBuilder() .setQuery("test") .addFields("field1") - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE_BOOLEAN) + .setFuzzyRewrite("constant_score_boolean") .build(); assertEquals("constant_score_boolean", fromProto(protoConstantScoreBoolean).fuzzyRewrite()); MultiMatchQuery protoScoringBoolean = MultiMatchQuery.newBuilder() .setQuery("test") .addFields("field1") - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_SCORING_BOOLEAN) + .setFuzzyRewrite("scoring_boolean") .build(); assertEquals("scoring_boolean", fromProto(protoScoringBoolean).fuzzyRewrite()); MultiMatchQuery protoTopTermsN = MultiMatchQuery.newBuilder() .setQuery("test") .addFields("field1") - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_N) + .setFuzzyRewrite("top_terms_10") .build(); - assertEquals("top_terms_n", fromProto(protoTopTermsN).fuzzyRewrite()); + assertEquals("top_terms_10", fromProto(protoTopTermsN).fuzzyRewrite()); MultiMatchQuery protoTopTermsBlended = MultiMatchQuery.newBuilder() .setQuery("test") .addFields("field1") - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_BLENDED_FREQS_N) + .setFuzzyRewrite("top_terms_blended_freqs_10") .build(); - assertEquals("top_terms_blended_freqs_n", fromProto(protoTopTermsBlended).fuzzyRewrite()); + assertEquals("top_terms_blended_freqs_10", fromProto(protoTopTermsBlended).fuzzyRewrite()); MultiMatchQuery protoTopTermsBoost = MultiMatchQuery.newBuilder() .setQuery("test") .addFields("field1") - .setFuzzyRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_BOOST_N) + .setFuzzyRewrite("top_terms_boost_10") .build(); - assertEquals("top_terms_boost_n", fromProto(protoTopTermsBoost).fuzzyRewrite()); + assertEquals("top_terms_boost_10", fromProto(protoTopTermsBoost).fuzzyRewrite()); } public void testFromProtoWithoutFuzzyRewrite() { diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoConverterTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoConverterTests.java index 25fbebea61b31..8b1be76a2e0ec 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoConverterTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoConverterTests.java @@ -34,7 +34,7 @@ public void testFromProto() { .setBoost(2.0f) .setXName("test_query") .setCaseInsensitive(true) - .setRewrite(org.opensearch.protobufs.MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setRewrite("constant_score") .build(); QueryContainer queryContainer = QueryContainer.newBuilder().setPrefix(prefixQuery).build(); diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoUtilsTests.java index 1f0cb6ab82f92..e372140c9a847 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/PrefixQueryBuilderProtoUtilsTests.java @@ -8,7 +8,6 @@ package org.opensearch.transport.grpc.proto.request.search.query; import org.opensearch.index.query.PrefixQueryBuilder; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.protobufs.PrefixQuery; import org.opensearch.test.OpenSearchTestCase; @@ -34,7 +33,7 @@ public void testFromProtoWithAllParameters() { PrefixQuery prefixQuery = PrefixQuery.newBuilder() .setField("name") .setValue("joh") - .setRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setRewrite("constant_score") .setCaseInsensitive(true) .setBoost(2.0f) .setXName("test_query") diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/RegexpQueryBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/RegexpQueryBuilderProtoUtilsTests.java index eea15682bbcb1..4088d257c0233 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/RegexpQueryBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/RegexpQueryBuilderProtoUtilsTests.java @@ -12,7 +12,6 @@ import org.opensearch.core.xcontent.XContentParser; import org.opensearch.index.query.RegexpFlag; import org.opensearch.index.query.RegexpQueryBuilder; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.protobufs.RegexpQuery; import org.opensearch.test.OpenSearchTestCase; @@ -57,7 +56,7 @@ public void testFromProtoWithAllFields() { .setFlags("INTERSECTION|COMPLEMENT") .setCaseInsensitive(true) .setMaxDeterminizedStates(20000) - .setRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setRewrite("constant_score") .build(); // Convert to RegexpQueryBuilder @@ -74,35 +73,23 @@ public void testFromProtoWithAllFields() { assertEquals("test_query", builder.queryName()); } - public void testFromProtoWithUnspecifiedRewrite() { - // Test that UNSPECIFIED rewrite method results in null rewrite - RegexpQuery proto = RegexpQuery.newBuilder() - .setField("test_field") - .setValue("test.*value") - .setRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) - .build(); - - RegexpQueryBuilder builder = fromProto(proto); - assertNull("UNSPECIFIED rewrite should result in null", builder.rewrite()); - } - public void testFromProtoWithDifferentRewriteMethods() { // Test all possible rewrite methods - MultiTermQueryRewrite[] rewriteMethods = { - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE_BOOLEAN, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_SCORING_BOOLEAN, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_N, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_BLENDED_FREQS_N, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_BOOST_N }; + String[] rewriteMethods = { + "constant_score", + "constant_score_boolean", + "scoring_boolean", + "top_terms_10", + "top_terms_blended_freqs_10", + "top_terms_boost_10" }; String[] expectedRewriteMethods = { "constant_score", "constant_score_boolean", "scoring_boolean", - "top_terms_n", - "top_terms_blended_freqs_n", - "top_terms_boost_n" }; + "top_terms_10", + "top_terms_blended_freqs_10", + "top_terms_boost_10" }; for (int i = 0; i < rewriteMethods.length; i++) { RegexpQuery proto = RegexpQuery.newBuilder() @@ -145,7 +132,7 @@ public void testFromProtoMatchesFromXContent() throws IOException { .setFlags("INTERSECTION") .setCaseInsensitive(true) .setMaxDeterminizedStates(20000) - .setRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setRewrite("constant_score") .setBoost(2.0f) .setXName("test_query") .build(); diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsLookupProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsLookupProtoUtilsTests.java index fde0a3d4eba41..7e79cb179625d 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsLookupProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsLookupProtoUtilsTests.java @@ -9,21 +9,20 @@ package org.opensearch.transport.grpc.proto.request.search.query; import org.opensearch.indices.TermsLookup; -import org.opensearch.protobufs.TermsLookupField; import org.opensearch.test.OpenSearchTestCase; public class TermsLookupProtoUtilsTests extends OpenSearchTestCase { public void testParseTermsLookupWithBasicFields() { - // Create a TermsLookupField instance with basic fields - TermsLookupField termsLookupField = TermsLookupField.newBuilder() + // Create a TermsLookup instance with basic fields (TermsLookupField was renamed to TermsLookup in protobufs 1.0.0) + org.opensearch.protobufs.TermsLookup termsLookupProto = org.opensearch.protobufs.TermsLookup.newBuilder() .setIndex("test_index") .setId("test_id") .setPath("test_path") .build(); // Call the method under test - TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupField); + TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupProto); // Verify the result assertNotNull("TermsLookup should not be null", termsLookup); @@ -35,8 +34,8 @@ public void testParseTermsLookupWithBasicFields() { } public void testParseTermsLookupWithStore() { - // Create a TermsLookupField instance with store field - TermsLookupField termsLookupField = TermsLookupField.newBuilder() + // Create a TermsLookup instance with store field + org.opensearch.protobufs.TermsLookup termsLookupProto = org.opensearch.protobufs.TermsLookup.newBuilder() .setIndex("test_index") .setId("test_id") .setPath("test_path") @@ -44,7 +43,7 @@ public void testParseTermsLookupWithStore() { .build(); // Call the method under test - TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupField); + TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupProto); // Verify the result assertNotNull("TermsLookup should not be null", termsLookup); @@ -62,15 +61,15 @@ public void testParseTermsLookupWithNullInput() { // This test verifies the bug fix for using index instead of id public void testParseTermsLookupWithDifferentIndexAndId() { - // Create a TermsLookupField instance with different index and id values - TermsLookupField termsLookupField = TermsLookupField.newBuilder() + // Create a TermsLookup instance with different index and id values + org.opensearch.protobufs.TermsLookup termsLookupProto = org.opensearch.protobufs.TermsLookup.newBuilder() .setIndex("test_index") .setId("test_id") .setPath("test_path") .build(); // Call the method under test - TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupField); + TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupProto); // Verify the result assertNotNull("TermsLookup should not be null", termsLookup); @@ -80,11 +79,15 @@ public void testParseTermsLookupWithDifferentIndexAndId() { } public void testParseTermsLookupWithEmptyFields() { - // Create a TermsLookupField instance with empty fields - TermsLookupField termsLookupField = TermsLookupField.newBuilder().setIndex("").setId("").setPath("").build(); + // Create a TermsLookup instance with empty fields + org.opensearch.protobufs.TermsLookup termsLookupProto = org.opensearch.protobufs.TermsLookup.newBuilder() + .setIndex("") + .setId("") + .setPath("") + .build(); // Call the method under test - TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupField); + TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupProto); // Verify the result assertNotNull("TermsLookup should not be null", termsLookup); @@ -94,8 +97,8 @@ public void testParseTermsLookupWithEmptyFields() { } public void testParseTermsLookupWithRouting() { - // Create a TermsLookupField instance with routing field - TermsLookupField termsLookupField = TermsLookupField.newBuilder() + // Create a TermsLookup instance with routing field + org.opensearch.protobufs.TermsLookup termsLookupProto = org.opensearch.protobufs.TermsLookup.newBuilder() .setIndex("test_index") .setId("test_id") .setPath("test_path") @@ -103,7 +106,7 @@ public void testParseTermsLookupWithRouting() { .build(); // Call the method under test - TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupField); + TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupProto); // Verify the result assertNotNull("TermsLookup should not be null", termsLookup); @@ -115,8 +118,8 @@ public void testParseTermsLookupWithRouting() { } public void testParseTermsLookupWithRoutingAndStore() { - // Create a TermsLookupField instance with both routing and store fields - TermsLookupField termsLookupField = TermsLookupField.newBuilder() + // Create a TermsLookup instance with both routing and store fields + org.opensearch.protobufs.TermsLookup termsLookupProto = org.opensearch.protobufs.TermsLookup.newBuilder() .setIndex("test_index") .setId("test_id") .setPath("test_path") @@ -125,7 +128,7 @@ public void testParseTermsLookupWithRoutingAndStore() { .build(); // Call the method under test - TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupField); + TermsLookup termsLookup = TermsLookupProtoUtils.parseTermsLookup(termsLookupProto); // Verify the result assertNotNull("TermsLookup should not be null", termsLookup); diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtilsTests.java index 50ab3c57942ea..6ffb5d8d94579 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtilsTests.java @@ -10,7 +10,6 @@ import org.opensearch.index.query.TermsQueryBuilder; import org.opensearch.protobufs.TermsQueryField; -import org.opensearch.protobufs.ValueType; import org.opensearch.test.OpenSearchTestCase; import static org.junit.Assert.assertEquals; @@ -61,32 +60,6 @@ public void testFromProtoWithEmptyTermsQueryField() { ); } - public void testParseValueTypeWithBitmap() { - // Test the parseValueType method with BITMAP - TermsQueryBuilder.ValueType valueType = TermsQueryBuilderProtoUtils.parseValueType(ValueType.VALUE_TYPE_BITMAP); - - assertEquals("Value type should be BITMAP", TermsQueryBuilder.ValueType.BITMAP, valueType); - } - - public void testParseValueTypeWithDefault() { - // Test the parseValueType method with DEFAULT - TermsQueryBuilder.ValueType valueType = TermsQueryBuilderProtoUtils.parseValueType(ValueType.VALUE_TYPE_DEFAULT); - - assertEquals("Value type should be DEFAULT", TermsQueryBuilder.ValueType.DEFAULT, valueType); - } - - public void testParseValueTypeWithUnspecified() { - // Test the parseValueType method with UNSPECIFIED - TermsQueryBuilder.ValueType valueType = TermsQueryBuilderProtoUtils.parseValueType(ValueType.VALUE_TYPE_UNSPECIFIED); - - assertEquals("Value type should be DEFAULT for UNSPECIFIED", TermsQueryBuilder.ValueType.DEFAULT, valueType); - } - - public void testParseValueTypeWithNull() { - - assertThrows(NullPointerException.class, () -> TermsQueryBuilderProtoUtils.parseValueType((ValueType) null)); - } - public void testFromProtoWithTermsLookupField() { org.opensearch.protobufs.TermsLookup lookup = org.opensearch.protobufs.TermsLookup.newBuilder() .setIndex("i") diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/WildcardQueryBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/WildcardQueryBuilderProtoUtilsTests.java index 9d28491971bc6..0ca0bc16fa0ae 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/WildcardQueryBuilderProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/WildcardQueryBuilderProtoUtilsTests.java @@ -11,7 +11,6 @@ import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.index.query.WildcardQueryBuilder; -import org.opensearch.protobufs.MultiTermQueryRewrite; import org.opensearch.protobufs.WildcardQuery; import org.opensearch.test.OpenSearchTestCase; @@ -52,7 +51,7 @@ public void testFromProtoWithAllFields() { .setBoost(2.0f) .setXName("test_query") .setCaseInsensitive(true) - .setRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setRewrite("constant_score") .build(); // Convert to WildcardQueryBuilder @@ -87,35 +86,23 @@ public void testFromProtoWithNeitherValueNorWildcard() { assertEquals("Either value or wildcard field must be set in wildcardQueryProto", exception.getMessage()); } - public void testFromProtoWithUnspecifiedRewrite() { - // Test that UNSPECIFIED rewrite method results in null rewrite - WildcardQuery proto = WildcardQuery.newBuilder() - .setField("test_field") - .setValue("test*value") - .setRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_UNSPECIFIED) - .build(); - - WildcardQueryBuilder builder = fromProto(proto); - assertNull("UNSPECIFIED rewrite should result in null", builder.rewrite()); - } - public void testFromProtoWithDifferentRewriteMethods() { - // Test all possible rewrite methods - MultiTermQueryRewrite[] rewriteMethods = { - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE_BOOLEAN, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_SCORING_BOOLEAN, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_N, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_BLENDED_FREQS_N, - MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_TOP_TERMS_BOOST_N }; + // Test all possible rewrite methods (rewrite is now a String in protobufs 1.0.0) + String[] rewriteMethods = { + "constant_score", + "constant_score_boolean", + "scoring_boolean", + "top_terms_10", + "top_terms_blended_freqs_10", + "top_terms_boost_10" }; String[] expectedRewriteMethods = { "constant_score", "constant_score_boolean", "scoring_boolean", - "top_terms_n", - "top_terms_blended_freqs_n", - "top_terms_boost_n" }; + "top_terms_10", + "top_terms_blended_freqs_10", + "top_terms_boost_10" }; for (int i = 0; i < rewriteMethods.length; i++) { WildcardQuery proto = WildcardQuery.newBuilder() @@ -154,7 +141,7 @@ public void testFromProtoMatchesFromXContent() throws IOException { .setField("test_field") .setValue("test*value") .setCaseInsensitive(true) - .setRewrite(MultiTermQueryRewrite.MULTI_TERM_QUERY_REWRITE_CONSTANT_SCORE) + .setRewrite("constant_score") .setBoost(2.0f) .setXName("test_query") .build(); diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/suggest/SuggestBuilderProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/suggest/SuggestBuilderProtoUtilsTests.java deleted file mode 100644 index af58b13a984a9..0000000000000 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/suggest/SuggestBuilderProtoUtilsTests.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.suggest; - -import org.opensearch.protobufs.Suggester; -import org.opensearch.search.suggest.SuggestBuilder; -import org.opensearch.test.OpenSearchTestCase; - -public class SuggestBuilderProtoUtilsTests extends OpenSearchTestCase { - - public void testFromProtoWithEmptySuggester() { - // Create an empty Suggester proto - Suggester suggesterProto = Suggester.newBuilder().build(); - - // Call the method under test - SuggestBuilder suggestBuilder = SuggestBuilderProtoUtils.fromProto(suggesterProto); - - // Verify the result - assertNotNull("SuggestBuilder should not be null", suggestBuilder); - } -} diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/common/FieldValueProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/common/FieldValueProtoUtilsTests.java index c24e868f3ea94..0c4f6a5f74415 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/common/FieldValueProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/common/FieldValueProtoUtilsTests.java @@ -165,6 +165,24 @@ public void testToProtoWithUnsupportedType() { assertTrue("Exception message should mention cannot convert", exception.getMessage().contains("Cannot convert")); } + public void testFromProtoWithUint64Value() { + // Create a FieldValue with UINT64_VALUE + // Using a value that fits in Java long (max long is 9223372036854775807L) + long uint64Value = 9223372036854775807L; + org.opensearch.protobufs.GeneralNumber generalNumber = org.opensearch.protobufs.GeneralNumber.newBuilder() + .setUint64Value(uint64Value) + .build(); + FieldValue fieldValue = FieldValue.newBuilder().setGeneralNumber(generalNumber).build(); + + // Convert from Protocol Buffer + Object result = FieldValueProtoUtils.fromProto(fieldValue); + + // Verify the conversion + assertNotNull("Result should not be null", result); + assertTrue("Result should be Long", result instanceof Long); + assertEquals("Uint64 value should match", uint64Value, result); + } + // Test enum for testing enum conversion private enum TestEnum { TEST_VALUE diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/OpenSearchExceptionProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/OpenSearchExceptionProtoUtilsTests.java index 421c0677d1bfc..61e8bd6a1810c 100644 --- a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/OpenSearchExceptionProtoUtilsTests.java +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/exceptions/OpenSearchExceptionProtoUtilsTests.java @@ -18,7 +18,7 @@ import org.opensearch.core.common.breaker.CircuitBreakingException; import org.opensearch.protobufs.ErrorCause; import org.opensearch.protobufs.ObjectMap; -import org.opensearch.protobufs.StringOrStringArray; +import org.opensearch.protobufs.StringArray; import org.opensearch.script.ScriptException; import org.opensearch.search.SearchParseException; import org.opensearch.search.aggregations.MultiBucketConsumerService; @@ -28,6 +28,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -168,14 +169,12 @@ public void testHeaderToProtoWithSingleValue() throws IOException { List values = Collections.singletonList("test-value"); // Convert to Protocol Buffer - Map.Entry entry = OpenSearchExceptionProtoUtils.headerToProto(key, values); + StringArray headerArray = OpenSearchExceptionProtoUtils.headerToProto(key, values); // Verify the conversion - assertNotNull("Entry should not be null", entry); - assertEquals("Key should match", key, entry.getKey()); - assertTrue("Should be a string value", entry.getValue().hasString()); - assertEquals("Value should match", "test-value", entry.getValue().getString()); - assertFalse("Should not have a string array", entry.getValue().hasStringArray()); + assertNotNull("Header array should not be null", headerArray); + assertEquals("Array should have correct size", 1, headerArray.getStringArrayCount()); + assertEquals("Value should match", "test-value", headerArray.getStringArray(0)); } public void testHeaderToProtoWithMultipleValues() throws IOException { @@ -184,17 +183,14 @@ public void testHeaderToProtoWithMultipleValues() throws IOException { List values = Arrays.asList("value1", "value2", "value3"); // Convert to Protocol Buffer - Map.Entry entry = OpenSearchExceptionProtoUtils.headerToProto(key, values); + StringArray headerArray = OpenSearchExceptionProtoUtils.headerToProto(key, values); // Verify the conversion - assertNotNull("Entry should not be null", entry); - assertEquals("Key should match", key, entry.getKey()); - assertFalse("Should not be a string value", entry.getValue().hasString()); - assertTrue("Should have a string array", entry.getValue().hasStringArray()); - assertEquals("Array should have correct size", 3, entry.getValue().getStringArray().getStringArrayCount()); - assertEquals("First value should match", "value1", entry.getValue().getStringArray().getStringArray(0)); - assertEquals("Second value should match", "value2", entry.getValue().getStringArray().getStringArray(1)); - assertEquals("Third value should match", "value3", entry.getValue().getStringArray().getStringArray(2)); + assertNotNull("Header array should not be null", headerArray); + assertEquals("Array should have correct size", 3, headerArray.getStringArrayCount()); + assertEquals("First value should match", "value1", headerArray.getStringArray(0)); + assertEquals("Second value should match", "value2", headerArray.getStringArray(1)); + assertEquals("Third value should match", "value3", headerArray.getStringArray(2)); } public void testHeaderToProtoWithEmptyValues() throws IOException { @@ -203,10 +199,10 @@ public void testHeaderToProtoWithEmptyValues() throws IOException { List values = Collections.emptyList(); // Convert to Protocol Buffer - Map.Entry entry = OpenSearchExceptionProtoUtils.headerToProto(key, values); + StringArray headerArray = OpenSearchExceptionProtoUtils.headerToProto(key, values); // Verify the conversion - assertNull("Entry should be null for empty values", entry); + assertNull("Header array should be null for empty values", headerArray); } public void testHeaderToProtoWithNullValues() throws IOException { @@ -215,10 +211,10 @@ public void testHeaderToProtoWithNullValues() throws IOException { List values = null; // Convert to Protocol Buffer - Map.Entry entry = OpenSearchExceptionProtoUtils.headerToProto(key, values); + StringArray headerArray = OpenSearchExceptionProtoUtils.headerToProto(key, values); // Verify the conversion - assertNull("Entry should be null for null values", entry); + assertNull("Header array should be null for null values", headerArray); } public void testHeaderToValueProtoWithSingleValue() throws IOException { @@ -434,4 +430,104 @@ public void testMetadataToProtoWithGenericOpenSearchException() { assertNotNull("Metadata should not be null", metadata); assertTrue("Metadata should be empty for generic exception", metadata.isEmpty()); } + + public void testInnerToProtoWithEmptyHeaders() throws IOException { + // Create an exception with empty headers + OpenSearchException exception = new OpenSearchException("Test exception"); + exception.addHeader("empty-header", Collections.emptyList()); + + // Convert to Protocol Buffer + ErrorCause errorCause = OpenSearchExceptionProtoUtils.toProto(exception); + + // Verify the conversion - empty headers should not be added + assertNotNull("ErrorCause should not be null", errorCause); + assertEquals("Should have the correct type", "exception", errorCause.getType()); + assertEquals("Should have the correct reason", "Test exception", errorCause.getReason()); + // Empty headers should not be added to the proto + assertEquals("Should have no headers", 0, errorCause.getHeaderCount()); + } + + public void testInnerToProtoWithNullHeaders() throws IOException { + // Create an exception with null header values + OpenSearchException exception = new OpenSearchException("Test exception"); + exception.addHeader("null-header", (List) null); + + // Convert to Protocol Buffer + ErrorCause errorCause = OpenSearchExceptionProtoUtils.toProto(exception); + + // Verify the conversion - null headers should not be added + assertNotNull("ErrorCause should not be null", errorCause); + assertEquals("Should have the correct type", "exception", errorCause.getType()); + assertEquals("Should have the correct reason", "Test exception", errorCause.getReason()); + // Null headers should not be added to the proto + assertEquals("Should have no headers", 0, errorCause.getHeaderCount()); + } + + public void testInnerToProtoWithMetadata() throws IOException { + // Create a FailedNodeException which has metadata (node_id) + FailedNodeException exception = new FailedNodeException(TEST_NODE_ID, "Test failed node", new IOException("IO error")); + + // Convert to Protocol Buffer + ErrorCause errorCause = OpenSearchExceptionProtoUtils.toProto(exception); + + // Verify the conversion - metadata should be included + assertNotNull("ErrorCause should not be null", errorCause); + assertTrue("Should have metadata", errorCause.hasMetadata()); + assertTrue("Metadata should have fields", errorCause.getMetadata().getFieldsCount() > 0); + } + + public void testInnerToProtoWithHeaders() throws IOException { + // Create an exception with headers + OpenSearchException exception = new OpenSearchException("Test exception"); + exception.addHeader("test-header", Arrays.asList("value1", "value2")); + + // Convert to Protocol Buffer + ErrorCause errorCause = OpenSearchExceptionProtoUtils.toProto(exception); + + // Verify the conversion - headers should be included + assertNotNull("ErrorCause should not be null", errorCause); + assertEquals("Should have the correct type", "exception", errorCause.getType()); + assertEquals("Should have the correct reason", "Test exception", errorCause.getReason()); + assertEquals("Should have 1 header", 1, errorCause.getHeaderCount()); + assertTrue("Should have test-header", errorCause.containsHeader("test-header")); + StringArray headerArray = errorCause.getHeaderOrDefault("test-header", null); + assertNotNull("Header array should not be null", headerArray); + assertEquals("Header should have 2 values", 2, headerArray.getStringArrayCount()); + } + + public void testToProtoWithWrappedException() throws IOException { + // Create an exception with a wrapped cause that will be unwrapped + IOException ioException = new IOException("IO error"); + OpenSearchException innerException = new OpenSearchException("Inner exception", ioException); + + // The toProto method unwraps causes, so when ex != exception, it calls generateThrowableProto + // We need to create a scenario where ExceptionsHelper.unwrapCause returns something different + // This is tricky to test directly, but we can test the generateThrowableProto path + ErrorCause errorCause = OpenSearchExceptionProtoUtils.generateThrowableProto(innerException); + + // Verify the conversion + assertNotNull("ErrorCause should not be null", errorCause); + assertEquals("Should have the correct type", "exception", errorCause.getType()); + } + + public void testInnerToProtoWithOpenSearchPrefixMetadata() throws IOException { + // Create an exception with metadata that has OPENSEARCH_PREFIX_KEY + // This tests the metadata loop that processes entries with the prefix + OpenSearchException exception = new OpenSearchException("Test exception") { + @Override + public Map> getMetadata() { + Map> metadata = new HashMap<>(); + metadata.put(OpenSearchException.OPENSEARCH_PREFIX_KEY + "custom_key", Arrays.asList("value1")); + return metadata; + } + }; + + // Convert to Protocol Buffer + ErrorCause errorCause = OpenSearchExceptionProtoUtils.toProto(exception); + + // Verify the conversion - metadata with prefix should be processed + assertNotNull("ErrorCause should not be null", errorCause); + assertTrue("Should have metadata", errorCause.hasMetadata()); + assertTrue("Metadata should have fields", errorCause.getMetadata().getFieldsCount() > 0); + } } diff --git a/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseSectionsProtoUtilsTests.java b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseSectionsProtoUtilsTests.java new file mode 100644 index 0000000000000..72d859f24c82e --- /dev/null +++ b/modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/response/search/SearchResponseSectionsProtoUtilsTests.java @@ -0,0 +1,381 @@ +/* + * 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.response.search; + +import org.opensearch.action.search.SearchResponse; +import org.opensearch.action.search.SearchResponseSections; +import org.opensearch.action.search.ShardSearchFailure; +import org.opensearch.common.unit.TimeValue; +import org.opensearch.search.SearchHits; +import org.opensearch.search.pipeline.ProcessorExecutionDetail; +import org.opensearch.test.OpenSearchTestCase; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class SearchResponseSectionsProtoUtilsTests extends OpenSearchTestCase { + + public void testToProtoWithProcessorResults() throws IOException { + // Create processor execution details + List processorResults = new ArrayList<>(); + + Map inputData1 = new HashMap<>(); + inputData1.put("key1", "value1"); + inputData1.put("key2", 42); + + Map outputData1 = new HashMap<>(); + outputData1.put("result", "success"); + + ProcessorExecutionDetail detail1 = new ProcessorExecutionDetail( + "processor1", + 100L, + inputData1, + outputData1, + ProcessorExecutionDetail.ProcessorStatus.SUCCESS, + null, + "tag1" + ); + processorResults.add(detail1); + + ProcessorExecutionDetail detail2 = new ProcessorExecutionDetail( + "processor2", + 50L, + null, + null, + ProcessorExecutionDetail.ProcessorStatus.FAIL, + "Error message", + null + ); + processorResults.add(detail2); + + // Create mock SearchResponseSections + SearchResponseSections mockSections = mock(SearchResponseSections.class); + when(mockSections.getProcessorResult()).thenReturn(processorResults); + when(mockSections.getSearchExtBuilders()).thenReturn(new ArrayList<>()); + + // Create mock SearchResponse + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mockSections); + when(mockResponse.getTook()).thenReturn(TimeValue.timeValueMillis(100)); + when(mockResponse.isTimedOut()).thenReturn(false); + when(mockResponse.getTotalShards()).thenReturn(5); + when(mockResponse.getSuccessfulShards()).thenReturn(5); + when(mockResponse.getSkippedShards()).thenReturn(0); + when(mockResponse.getFailedShards()).thenReturn(0); + when(mockResponse.getShardFailures()).thenReturn(new ShardSearchFailure[0]); + when(mockResponse.getClusters()).thenReturn(new SearchResponse.Clusters(0, 0, 0)); + when(mockResponse.getAggregations()).thenReturn(null); + when(mockResponse.getSuggest()).thenReturn(null); + when(mockResponse.getProfileResults()).thenReturn(null); + + // Call the method under test + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + SearchResponseSectionsProtoUtils.toProto(builder, mockResponse); + org.opensearch.protobufs.SearchResponse protoResponse = builder.build(); + + // Verify processor results + assertNotNull("Proto response should not be null", protoResponse); + assertEquals("Should have 2 processor results", 2, protoResponse.getProcessorResultsCount()); + + org.opensearch.protobufs.ProcessorExecutionDetail protoDetail1 = protoResponse.getProcessorResults(0); + assertEquals("Processor name should match", "processor1", protoDetail1.getProcessorName()); + assertEquals("Duration should match", 100L, protoDetail1.getDurationMillis()); + assertEquals("Tag should match", "tag1", protoDetail1.getTag()); + assertEquals("Status should match", "success", protoDetail1.getStatus()); + assertTrue("Should have input data", protoDetail1.hasInputData()); + assertTrue("Should have output data", protoDetail1.hasOutputData()); + assertFalse("Should not have error", protoDetail1.hasError()); + + org.opensearch.protobufs.ProcessorExecutionDetail protoDetail2 = protoResponse.getProcessorResults(1); + assertEquals("Processor name should match", "processor2", protoDetail2.getProcessorName()); + assertEquals("Duration should match", 50L, protoDetail2.getDurationMillis()); + assertEquals("Status should match", "fail", protoDetail2.getStatus()); + assertEquals("Error message should match", "Error message", protoDetail2.getError()); + assertFalse("Should not have tag", protoDetail2.hasTag()); + } + + public void testToProtoWithEmptyProcessorResults() throws IOException { + // Create mock SearchResponseSections with empty processor results + SearchResponseSections mockSections = mock(SearchResponseSections.class); + when(mockSections.getProcessorResult()).thenReturn(new ArrayList<>()); + when(mockSections.getSearchExtBuilders()).thenReturn(new ArrayList<>()); + + // Create mock SearchResponse + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mockSections); + when(mockResponse.getTook()).thenReturn(TimeValue.timeValueMillis(100)); + when(mockResponse.isTimedOut()).thenReturn(false); + when(mockResponse.getTotalShards()).thenReturn(5); + when(mockResponse.getSuccessfulShards()).thenReturn(5); + when(mockResponse.getSkippedShards()).thenReturn(0); + when(mockResponse.getFailedShards()).thenReturn(0); + when(mockResponse.getShardFailures()).thenReturn(new ShardSearchFailure[0]); + when(mockResponse.getClusters()).thenReturn(new SearchResponse.Clusters(0, 0, 0)); + + // Call the method under test + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + SearchResponseSectionsProtoUtils.toProto(builder, mockResponse); + org.opensearch.protobufs.SearchResponse protoResponse = builder.build(); + + // Verify no processor results + assertEquals("Should have 0 processor results", 0, protoResponse.getProcessorResultsCount()); + } + + public void testToProtoWithNullProcessorResults() throws IOException { + // Create mock SearchResponseSections with null processor results + SearchResponseSections mockSections = mock(SearchResponseSections.class); + when(mockSections.getProcessorResult()).thenReturn(null); + when(mockSections.getSearchExtBuilders()).thenReturn(new ArrayList<>()); + + // Create mock SearchResponse + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mockSections); + when(mockResponse.getTook()).thenReturn(TimeValue.timeValueMillis(100)); + when(mockResponse.isTimedOut()).thenReturn(false); + when(mockResponse.getTotalShards()).thenReturn(5); + when(mockResponse.getSuccessfulShards()).thenReturn(5); + when(mockResponse.getSkippedShards()).thenReturn(0); + when(mockResponse.getFailedShards()).thenReturn(0); + when(mockResponse.getShardFailures()).thenReturn(new ShardSearchFailure[0]); + when(mockResponse.getClusters()).thenReturn(new SearchResponse.Clusters(0, 0, 0)); + + // Call the method under test + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + SearchResponseSectionsProtoUtils.toProto(builder, mockResponse); + org.opensearch.protobufs.SearchResponse protoResponse = builder.build(); + + // Verify no processor results + assertEquals("Should have 0 processor results", 0, protoResponse.getProcessorResultsCount()); + } + + public void testToProtoWithProcessorResultNullFields() throws IOException { + // Create processor execution detail with null fields + List processorResults = new ArrayList<>(); + ProcessorExecutionDetail detail = new ProcessorExecutionDetail( + "processor1", + 100L, + null, + null, + ProcessorExecutionDetail.ProcessorStatus.SUCCESS, + null, + null + ); + processorResults.add(detail); + + // Create mock SearchResponseSections + SearchResponseSections mockSections = mock(SearchResponseSections.class); + when(mockSections.getProcessorResult()).thenReturn(processorResults); + when(mockSections.getSearchExtBuilders()).thenReturn(new ArrayList<>()); + + // Create mock SearchResponse + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mockSections); + when(mockResponse.getTook()).thenReturn(TimeValue.timeValueMillis(100)); + when(mockResponse.isTimedOut()).thenReturn(false); + when(mockResponse.getTotalShards()).thenReturn(5); + when(mockResponse.getSuccessfulShards()).thenReturn(5); + when(mockResponse.getSkippedShards()).thenReturn(0); + when(mockResponse.getFailedShards()).thenReturn(0); + when(mockResponse.getShardFailures()).thenReturn(new ShardSearchFailure[0]); + when(mockResponse.getClusters()).thenReturn(new SearchResponse.Clusters(0, 0, 0)); + when(mockResponse.getAggregations()).thenReturn(null); + when(mockResponse.getSuggest()).thenReturn(null); + when(mockResponse.getProfileResults()).thenReturn(null); + + // Call the method under test + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + SearchResponseSectionsProtoUtils.toProto(builder, mockResponse); + org.opensearch.protobufs.SearchResponse protoResponse = builder.build(); + + // Verify processor result + assertEquals("Should have 1 processor result", 1, protoResponse.getProcessorResultsCount()); + org.opensearch.protobufs.ProcessorExecutionDetail protoDetail = protoResponse.getProcessorResults(0); + assertEquals("Processor name should match", "processor1", protoDetail.getProcessorName()); + assertEquals("Duration should match", 100L, protoDetail.getDurationMillis()); + assertEquals("Status should match", "success", protoDetail.getStatus()); + assertFalse("Should not have input data", protoDetail.hasInputData()); + assertFalse("Should not have output data", protoDetail.hasOutputData()); + assertFalse("Should not have error", protoDetail.hasError()); + assertFalse("Should not have tag", protoDetail.hasTag()); + } + + public void testToProtoWithProcessorResultNullProcessorName() throws IOException { + // Create processor execution detail with null processor name + List processorResults = new ArrayList<>(); + ProcessorExecutionDetail detail = new ProcessorExecutionDetail( + null, + 100L, + null, + null, + ProcessorExecutionDetail.ProcessorStatus.SUCCESS, + null, + null + ); + processorResults.add(detail); + + // Create mock SearchResponseSections + SearchResponseSections mockSections = mock(SearchResponseSections.class); + when(mockSections.getProcessorResult()).thenReturn(processorResults); + when(mockSections.getSearchExtBuilders()).thenReturn(new ArrayList<>()); + + // Create mock SearchResponse + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mockSections); + when(mockResponse.getTook()).thenReturn(TimeValue.timeValueMillis(100)); + when(mockResponse.isTimedOut()).thenReturn(false); + when(mockResponse.getTotalShards()).thenReturn(5); + when(mockResponse.getSuccessfulShards()).thenReturn(5); + when(mockResponse.getSkippedShards()).thenReturn(0); + when(mockResponse.getFailedShards()).thenReturn(0); + when(mockResponse.getShardFailures()).thenReturn(new ShardSearchFailure[0]); + when(mockResponse.getClusters()).thenReturn(new SearchResponse.Clusters(0, 0, 0)); + when(mockResponse.getAggregations()).thenReturn(null); + when(mockResponse.getSuggest()).thenReturn(null); + when(mockResponse.getProfileResults()).thenReturn(null); + + // Call the method under test + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + SearchResponseSectionsProtoUtils.toProto(builder, mockResponse); + org.opensearch.protobufs.SearchResponse protoResponse = builder.build(); + + // Verify processor result - null processor name should not be set + assertEquals("Should have 1 processor result", 1, protoResponse.getProcessorResultsCount()); + org.opensearch.protobufs.ProcessorExecutionDetail protoDetail = protoResponse.getProcessorResults(0); + assertEquals("Duration should match", 100L, protoDetail.getDurationMillis()); + assertFalse("Should not have processor name", protoDetail.hasProcessorName()); + } + + public void testToProtoWithProcessorResultNullStatus() throws IOException { + // Create processor execution detail with null status + List processorResults = new ArrayList<>(); + ProcessorExecutionDetail detail = new ProcessorExecutionDetail("processor1", 100L, null, null, null, null, null); + processorResults.add(detail); + + // Create mock SearchResponseSections + SearchResponseSections mockSections = mock(SearchResponseSections.class); + when(mockSections.getProcessorResult()).thenReturn(processorResults); + when(mockSections.getSearchExtBuilders()).thenReturn(new ArrayList<>()); + + // Create mock SearchResponse + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mockSections); + when(mockResponse.getTook()).thenReturn(TimeValue.timeValueMillis(100)); + when(mockResponse.isTimedOut()).thenReturn(false); + when(mockResponse.getTotalShards()).thenReturn(5); + when(mockResponse.getSuccessfulShards()).thenReturn(5); + when(mockResponse.getSkippedShards()).thenReturn(0); + when(mockResponse.getFailedShards()).thenReturn(0); + when(mockResponse.getShardFailures()).thenReturn(new ShardSearchFailure[0]); + when(mockResponse.getClusters()).thenReturn(new SearchResponse.Clusters(0, 0, 0)); + when(mockResponse.getAggregations()).thenReturn(null); + when(mockResponse.getSuggest()).thenReturn(null); + when(mockResponse.getProfileResults()).thenReturn(null); + + // Call the method under test + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + SearchResponseSectionsProtoUtils.toProto(builder, mockResponse); + org.opensearch.protobufs.SearchResponse protoResponse = builder.build(); + + // Verify processor result - null status should not be set + assertEquals("Should have 1 processor result", 1, protoResponse.getProcessorResultsCount()); + org.opensearch.protobufs.ProcessorExecutionDetail protoDetail = protoResponse.getProcessorResults(0); + assertEquals("Processor name should match", "processor1", protoDetail.getProcessorName()); + assertEquals("Duration should match", 100L, protoDetail.getDurationMillis()); + assertFalse("Should not have status", protoDetail.hasStatus()); + } + + public void testToProtoThrowsUnsupportedOperationExceptionForAggregations() { + // Create mock SearchResponse with aggregations + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mock(SearchResponseSections.class)); + when(mockResponse.getAggregations()).thenReturn(mock(org.opensearch.search.aggregations.Aggregations.class)); + + // Call the method under test - should throw UnsupportedOperationException + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + UnsupportedOperationException exception = expectThrows( + UnsupportedOperationException.class, + () -> SearchResponseSectionsProtoUtils.toProto(builder, mockResponse) + ); + assertEquals("aggregation responses are not supported yet", exception.getMessage()); + } + + public void testToProtoThrowsUnsupportedOperationExceptionForSuggest() { + // Create mock SearchResponse with suggest + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mock(SearchResponseSections.class)); + when(mockResponse.getAggregations()).thenReturn(null); + when(mockResponse.getSuggest()).thenReturn(mock(org.opensearch.search.suggest.Suggest.class)); + + // Call the method under test - should throw UnsupportedOperationException + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + UnsupportedOperationException exception = expectThrows( + UnsupportedOperationException.class, + () -> SearchResponseSectionsProtoUtils.toProto(builder, mockResponse) + ); + assertEquals("suggest responses are not supported yet", exception.getMessage()); + } + + public void testToProtoThrowsUnsupportedOperationExceptionForProfileResults() { + // Create mock SearchResponse with profile results + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mock(SearchResponseSections.class)); + when(mockResponse.getAggregations()).thenReturn(null); + when(mockResponse.getSuggest()).thenReturn(null); + Map profileResults = new HashMap<>(); + profileResults.put("shard1", mock(org.opensearch.search.profile.ProfileShardResult.class)); + when(mockResponse.getProfileResults()).thenReturn(profileResults); + + // Call the method under test - should throw UnsupportedOperationException + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + UnsupportedOperationException exception = expectThrows( + UnsupportedOperationException.class, + () -> SearchResponseSectionsProtoUtils.toProto(builder, mockResponse) + ); + assertEquals("profile results are not supported yet", exception.getMessage()); + } + + public void testToProtoThrowsUnsupportedOperationExceptionForSearchExtBuilders() { + // Create mock SearchResponseSections with search ext builders + SearchResponseSections mockSections = mock(SearchResponseSections.class); + List extBuilders = new ArrayList<>(); + extBuilders.add(mock(org.opensearch.search.SearchExtBuilder.class)); + when(mockSections.getSearchExtBuilders()).thenReturn(extBuilders); + + // Create mock SearchResponse + SearchResponse mockResponse = mock(SearchResponse.class); + when(mockResponse.getHits()).thenReturn(SearchHits.empty()); + when(mockResponse.getInternalResponse()).thenReturn(mockSections); + when(mockResponse.getAggregations()).thenReturn(null); + when(mockResponse.getSuggest()).thenReturn(null); + when(mockResponse.getProfileResults()).thenReturn(null); + + // Call the method under test - should throw UnsupportedOperationException + org.opensearch.protobufs.SearchResponse.Builder builder = org.opensearch.protobufs.SearchResponse.newBuilder(); + UnsupportedOperationException exception = expectThrows( + UnsupportedOperationException.class, + () -> SearchResponseSectionsProtoUtils.toProto(builder, mockResponse) + ); + assertEquals("ext builder responses are not supported yet", exception.getMessage()); + } +} diff --git a/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/HighlightBuilder.java b/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/HighlightBuilder.java index 44ef3a90395b8..dc4f6609a27bc 100644 --- a/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/HighlightBuilder.java +++ b/server/src/main/java/org/opensearch/search/fetch/subphase/highlight/HighlightBuilder.java @@ -92,9 +92,9 @@ public class HighlightBuilder extends AbstractHighlighterBuilder" }; + public static final String[] DEFAULT_PRE_TAGS = new String[] { "" }; /** the default closing tag */ - static final String[] DEFAULT_POST_TAGS = new String[] { "" }; + public static final String[] DEFAULT_POST_TAGS = new String[] { "" }; /** the default opening tags when {@code tag_schema = "styled"} */ public static final String[] DEFAULT_STYLED_PRE_TAG = { diff --git a/server/src/main/java/org/opensearch/search/pipeline/ProcessorExecutionDetail.java b/server/src/main/java/org/opensearch/search/pipeline/ProcessorExecutionDetail.java index 202323dfa8789..8edd41076fb53 100644 --- a/server/src/main/java/org/opensearch/search/pipeline/ProcessorExecutionDetail.java +++ b/server/src/main/java/org/opensearch/search/pipeline/ProcessorExecutionDetail.java @@ -130,6 +130,14 @@ public ProcessorStatus getStatus() { return status; } + public String getErrorMessage() { + return errorMessage; + } + + public String getTag() { + return tag; + } + /** * Adds or updates the input data for this processor execution detail. * diff --git a/server/src/test/java/org/opensearch/search/pipeline/ProcessorExecutionDetailTests.java b/server/src/test/java/org/opensearch/search/pipeline/ProcessorExecutionDetailTests.java index 0a5b62add6aa1..2749d7a4ec832 100644 --- a/server/src/test/java/org/opensearch/search/pipeline/ProcessorExecutionDetailTests.java +++ b/server/src/test/java/org/opensearch/search/pipeline/ProcessorExecutionDetailTests.java @@ -184,4 +184,52 @@ public void testFromXContentWithPRocessorError() throws IOException { assertEquals(ProcessorExecutionDetail.ProcessorStatus.FAIL, detail.getStatus()); } } + + public void testGetErrorMessage() { + ProcessorExecutionDetail detail = new ProcessorExecutionDetail( + "testProcessor", + 123L, + Map.of("key1", "value1"), + List.of(1, 2, 3), + ProcessorExecutionDetail.ProcessorStatus.FAIL, + "processor 1 fail", + "tag123" + ); + assertEquals("processor 1 fail", detail.getErrorMessage()); + + ProcessorExecutionDetail detailNoError = new ProcessorExecutionDetail( + "testProcessor", + 123L, + Map.of("key1", "value1"), + List.of(1, 2, 3), + ProcessorExecutionDetail.ProcessorStatus.SUCCESS, + null, + null + ); + assertNull(detailNoError.getErrorMessage()); + } + + public void testGetTag() { + ProcessorExecutionDetail detail = new ProcessorExecutionDetail( + "testProcessor", + 123L, + Map.of("key1", "value1"), + List.of(1, 2, 3), + ProcessorExecutionDetail.ProcessorStatus.SUCCESS, + null, + "tag123" + ); + assertEquals("tag123", detail.getTag()); + + ProcessorExecutionDetail detailNoTag = new ProcessorExecutionDetail( + "testProcessor", + 123L, + Map.of("key1", "value1"), + List.of(1, 2, 3), + ProcessorExecutionDetail.ProcessorStatus.SUCCESS, + null, + null + ); + assertNull(detailNoTag.getTag()); + } }