Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Bump opensearch-protobufs dependency to 0.24.0 and update transport-grpc module compatibility ([#20059](https://github.com/opensearch-project/OpenSearch/pull/20059))

- Refactor the ShardStats, WarmerStats and IndexingPressureStats class to use the Builder pattern instead of constructors ([#19966](https://github.com/opensearch-project/OpenSearch/pull/19966))
- Throw exceptions for currently unsupported GRPC request-side fields ([#20162](https://github.com/opensearch-project/OpenSearch/pull/20162))

### Fixed
- Fix Allocation and Rebalance Constraints of WeightFunction are incorrectly reset ([#19012](https://github.com/opensearch-project/OpenSearch/pull/19012))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public static org.opensearch.action.bulk.BulkRequest prepareRequest(BulkRequest
)
);

// Type is a deprecated field according to the spec, thus no plans to support it
if (request.hasType()) {
throw new UnsupportedOperationException("type param is not supported");
}

// TODO support global_params
if (request.hasGlobalParams()) {
throw new UnsupportedOperationException("global_params param is not supported yet");
}

return bulkRequest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ protected static void parseSearchRequest(
? parseTimeValue(request.getCancelAfterTimeInterval(), null, "cancel_after_time_interval")
: null
);

// TODO support typed_keys
if (request.hasTypedKeys()) {
throw new UnsupportedOperationException("typed_keys param is not supported yet");
}

// TODO support global_params
if (request.hasGlobalParams()) {
throw new UnsupportedOperationException("global_params param is not supported yet");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.opensearch.transport.grpc.proto.request.common.ScriptProtoUtils;
import org.opensearch.transport.grpc.proto.request.search.query.AbstractQueryBuilderProtoUtils;
import org.opensearch.transport.grpc.proto.request.search.sort.SortBuilderProtoUtils;
import org.opensearch.transport.grpc.proto.request.search.suggest.SuggestBuilderProtoUtils;
import org.opensearch.transport.grpc.spi.QueryBuilderProtoConverterRegistry;

import java.io.IOException;
Expand Down Expand Up @@ -154,15 +153,18 @@ private static void parseNonQueryFields(
}

// TODO support aggregations
/*
if(protoRequest.hasAggs()){}
*/
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
if (protoRequest.hasSuggest()) {
searchSourceBuilder.suggest(SuggestBuilderProtoUtils.fromProto(protoRequest.getSuggest()));
throw new UnsupportedOperationException("suggest param is not supported yet");
// searchSourceBuilder.suggest(SuggestBuilderProtoUtils.fromProto(protoRequest.getSuggest()));
}
if (protoRequest.getRescoreCount() > 0) {
for (Rescore rescore : protoRequest.getRescoreList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ private static TermsLookup parseTermsLookup(org.opensearch.protobufs.TermsLookup
if (lookup.hasRouting()) {
tl.routing(lookup.getRouting());
}
if (lookup.hasStore()) {
tl.store(lookup.getStore());
}
return tl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,30 @@ public void testPrepareRequestWithRefreshFalse() {
assertNotNull("BulkRequest should not be null", bulkRequest);
assertEquals("Refresh policy should be NONE", WriteRequest.RefreshPolicy.NONE, bulkRequest.getRefreshPolicy());
}

public void testPrepareRequestWithTypeThrowsUnsupportedOperationException() {
// Create a protobuf BulkRequest with deprecated type field
BulkRequest request = BulkRequest.newBuilder().setType("_doc").build();

// Call prepareRequest, should throw UnsupportedOperationException
UnsupportedOperationException exception = expectThrows(
UnsupportedOperationException.class,
() -> BulkRequestProtoUtils.prepareRequest(request)
);

assertEquals("type param is not supported", exception.getMessage());
}

public void testPrepareRequestWithGlobalParamsThrowsUnsupportedOperationException() {
// Create a protobuf BulkRequest with global_params
BulkRequest request = BulkRequest.newBuilder().setGlobalParams(org.opensearch.protobufs.GlobalParams.newBuilder().build()).build();

// Call prepareRequest, should throw UnsupportedOperationException
UnsupportedOperationException exception = expectThrows(
UnsupportedOperationException.class,
() -> BulkRequestProtoUtils.prepareRequest(request)
);

assertEquals("global_params param is not supported yet", exception.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,40 @@ public void testParseSearchSourceWithInvalidTerminateAfter() throws IOException
);
}

public void testParseSearchRequestWithTypedKeysThrowsUnsupportedOperationException() throws IOException {
// Create a protobuf SearchRequest with typed_keys
org.opensearch.protobufs.SearchRequest protoRequest = org.opensearch.protobufs.SearchRequest.newBuilder()
.setTypedKeys(true)
.build();

// Create a SearchRequest to populate
SearchRequest searchRequest = new SearchRequest();

// Call the method under test, should throw UnsupportedOperationException
UnsupportedOperationException exception = expectThrows(
UnsupportedOperationException.class,
() -> SearchRequestProtoUtils.parseSearchRequest(searchRequest, protoRequest, namedWriteableRegistry, size -> {}, queryUtils)
);

assertEquals("typed_keys param is not supported yet", exception.getMessage());
}

public void testParseSearchRequestWithGlobalParamsThrowsUnsupportedOperationException() throws IOException {
// Create a protobuf SearchRequest with global_params
org.opensearch.protobufs.SearchRequest protoRequest = org.opensearch.protobufs.SearchRequest.newBuilder()
.setGlobalParams(org.opensearch.protobufs.GlobalParams.newBuilder().build())
.build();

// Create a SearchRequest to populate
SearchRequest searchRequest = new SearchRequest();

// Call the method under test, should throw UnsupportedOperationException
UnsupportedOperationException exception = expectThrows(
UnsupportedOperationException.class,
() -> SearchRequestProtoUtils.parseSearchRequest(searchRequest, protoRequest, namedWriteableRegistry, size -> {}, queryUtils)
);

assertEquals("global_params param is not supported yet", exception.getMessage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,24 @@ 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()
Expand Down Expand Up @@ -732,9 +750,12 @@ public void testParseProtoWithSuggest() throws IOException {

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

SearchSourceBuilderProtoUtils.parseProto(searchSourceBuilder, protoRequest, queryUtils);

assertNotNull("SuggestBuilder should not be null", searchSourceBuilder.suggest());
// 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());
}

public void testParseProtoWithXSourceIncludes() throws IOException {
Expand Down
Loading