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 @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add support for Combined Fields query ([#18724](https://github.com/opensearch-project/OpenSearch/pull/18724))
- Make GRPC transport extensible to allow plugins to register and expose their own GRPC services ([#18516](https://github.com/opensearch-project/OpenSearch/pull/18516))
- Added approximation support for range queries with now in date field ([#18511](https://github.com/opensearch-project/OpenSearch/pull/18511))
- Upgrade to protobufs 0.6.0 and clean up deprecated TermQueryProtoUtils code ([#18880](https://github.com/opensearch-project/OpenSearch/pull/18880))

### Changed
- Update Subject interface to use CheckedRunnable ([#18570](https://github.com/opensearch-project/OpenSearch/issues/18570))
Expand Down
2 changes: 1 addition & 1 deletion plugins/transport-grpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
implementation "io.grpc:grpc-stub:${versions.grpc}"
implementation "io.grpc:grpc-util:${versions.grpc}"
implementation "io.perfmark:perfmark-api:0.27.0"
implementation "org.opensearch:protobufs:0.4.0"
implementation "org.opensearch:protobufs:0.6.0"
testImplementation project(':test:framework')
}

Expand Down
1 change: 0 additions & 1 deletion plugins/transport-grpc/licenses/protobufs-0.4.0.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions plugins/transport-grpc/licenses/protobufs-0.6.0.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1675c5085e1376fd1a107b87f7e325944ab5b4dc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ protected static MatchAllQueryBuilder fromProto(MatchAllQuery matchAllQueryProto
matchAllQueryBuilder.boost(matchAllQueryProto.getBoost());
}

if (matchAllQueryProto.hasName()) {
matchAllQueryBuilder.queryName(matchAllQueryProto.getName());
if (matchAllQueryProto.hasUnderscoreName()) {
matchAllQueryBuilder.queryName(matchAllQueryProto.getUnderscoreName());
}

return matchAllQueryBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected static MatchNoneQueryBuilder fromProto(MatchNoneQuery matchNoneQueryPr
matchNoneQueryBuilder.boost(matchNoneQueryProto.getBoost());
}

if (matchNoneQueryProto.hasName()) {
matchNoneQueryBuilder.queryName(matchNoneQueryProto.getName());
if (matchNoneQueryProto.hasUnderscoreName()) {
matchNoneQueryBuilder.queryName(matchNoneQueryProto.getUnderscoreName());
}

return matchNoneQueryBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import org.opensearch.protobufs.FieldValue;
import org.opensearch.protobufs.TermQuery;

import java.util.Map;

/**
* Utility class for converting TermQuery Protocol Buffers to OpenSearch objects.
* This class provides methods to transform Protocol Buffer representations of term queries
Expand Down Expand Up @@ -45,8 +43,8 @@ protected static TermQueryBuilder fromProto(TermQuery termQueryProto) {
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
boolean caseInsensitive = TermQueryBuilder.DEFAULT_CASE_INSENSITIVITY;

if (termQueryProto.hasName()) {
queryName = termQueryProto.getName();
if (termQueryProto.hasUnderscoreName()) {
queryName = termQueryProto.getUnderscoreName();
}
if (termQueryProto.hasBoost()) {
boost = termQueryProto.getBoost();
Expand Down Expand Up @@ -102,92 +100,4 @@ protected static TermQueryBuilder fromProto(TermQuery termQueryProto) {
return termQuery;
}

/**
* Converts a Protocol Buffer TermQuery map to an OpenSearch TermQueryBuilder.
* Similar to {@link TermQueryBuilder#fromXContent(XContentParser)}, this method
* parses the Protocol Buffer representation and creates a properly configured
* TermQueryBuilder with the appropriate field name, value, boost, query name,
* and case sensitivity settings.
*
* @param termQueryProto The map of field names to Protocol Buffer TermQuery objects
* @return A configured TermQueryBuilder instance
* @throws IllegalArgumentException if the term query map has more than one element,
* if the field value type is not supported, or if the term query field value is not recognized
* @deprecated Use {@link #fromProto(TermQuery)} instead for the new protobuf structure
*/
@Deprecated
protected static TermQueryBuilder fromProto(Map<String, TermQuery> termQueryProto) {
String queryName = null;
String fieldName = null;
Object value = null;
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
boolean caseInsensitive = TermQueryBuilder.DEFAULT_CASE_INSENSITIVITY;

if (termQueryProto.size() > 1) {
throw new IllegalArgumentException("Term query can only have 1 element in the map");
}

for (Map.Entry<String, TermQuery> entry : termQueryProto.entrySet()) {

fieldName = entry.getKey();

TermQuery termQuery = entry.getValue();

if (termQuery.hasName()) {
queryName = termQuery.getName();
}
if (termQuery.hasBoost()) {
boost = termQuery.getBoost();
}

FieldValue fieldValue = termQuery.getValue();

switch (fieldValue.getTypeCase()) {
case GENERAL_NUMBER:
switch (fieldValue.getGeneralNumber().getValueCase()) {
case INT32_VALUE:
value = fieldValue.getGeneralNumber().getInt32Value();
break;
case INT64_VALUE:
value = fieldValue.getGeneralNumber().getInt64Value();
break;
case FLOAT_VALUE:
value = fieldValue.getGeneralNumber().getFloatValue();
break;
case DOUBLE_VALUE:
value = fieldValue.getGeneralNumber().getDoubleValue();
break;
default:
throw new IllegalArgumentException(
"Unsupported general nunber type: " + fieldValue.getGeneralNumber().getValueCase()
);
}
break;
case STRING_VALUE:
value = fieldValue.getStringValue();
break;
case OBJECT_MAP:
value = ObjectMapProtoUtils.fromProto(fieldValue.getObjectMap());
break;
case BOOL_VALUE:
value = fieldValue.getBoolValue();
break;
default:
throw new IllegalArgumentException("TermQuery field value not recognized");
}

if (termQuery.hasCaseInsensitive()) {
caseInsensitive = termQuery.getCaseInsensitive();
}

}
TermQueryBuilder termQuery = new TermQueryBuilder(fieldName, value);
termQuery.boost(boost);
if (queryName != null) {
termQuery.queryName(queryName);
}
termQuery.caseInsensitive(caseInsensitive);

return termQuery;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ protected static TermsQueryBuilder fromProto(TermsQueryField termsQueryProto) {
boost = termsQueryProto.getBoost();
}

if (termsQueryProto.hasName()) {
queryName = termsQueryProto.getName();
if (termsQueryProto.hasUnderscoreName()) {
queryName = termsQueryProto.getUnderscoreName();
}

// TODO: remove this parameter when backporting to under OS 2.17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testGetHandledQueryCase() {

public void testFromProto() {
// Create a QueryContainer with MatchAllQuery
MatchAllQuery matchAllQuery = MatchAllQuery.newBuilder().setBoost(2.0f).setName("test_query").build();
MatchAllQuery matchAllQuery = MatchAllQuery.newBuilder().setBoost(2.0f).setUnderscoreName("test_query").build();
QueryContainer queryContainer = QueryContainer.newBuilder().setMatchAll(matchAllQuery).build();

// Convert the query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testFromProtoWithBoost() {

public void testFromProtoWithName() {
// Create a protobuf MatchAllQuery with name
MatchAllQuery matchAllQueryProto = MatchAllQuery.newBuilder().setName("test_query").build();
MatchAllQuery matchAllQueryProto = MatchAllQuery.newBuilder().setUnderscoreName("test_query").build();

// Call the method under test
MatchAllQueryBuilder matchAllQueryBuilder = MatchAllQueryBuilderProtoUtils.fromProto(matchAllQueryProto);
Expand All @@ -55,7 +55,7 @@ public void testFromProtoWithName() {

public void testFromProtoWithBoostAndName() {
// Create a protobuf MatchAllQuery with boost and name
MatchAllQuery matchAllQueryProto = MatchAllQuery.newBuilder().setBoost(3.0f).setName("test_query").build();
MatchAllQuery matchAllQueryProto = MatchAllQuery.newBuilder().setBoost(3.0f).setUnderscoreName("test_query").build();

// Call the method under test
MatchAllQueryBuilder matchAllQueryBuilder = MatchAllQueryBuilderProtoUtils.fromProto(matchAllQueryProto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testGetHandledQueryCase() {

public void testFromProto() {
// Create a QueryContainer with MatchNoneQuery
MatchNoneQuery matchNoneQuery = MatchNoneQuery.newBuilder().setBoost(2.0f).setName("test_query").build();
MatchNoneQuery matchNoneQuery = MatchNoneQuery.newBuilder().setBoost(2.0f).setUnderscoreName("test_query").build();
QueryContainer queryContainer = QueryContainer.newBuilder().setMatchNone(matchNoneQuery).build();

// Convert the query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testFromProtoWithBoost() {

public void testFromProtoWithName() {
// Create a protobuf MatchNoneQuery with name
MatchNoneQuery matchNoneQueryProto = MatchNoneQuery.newBuilder().setName("test_query").build();
MatchNoneQuery matchNoneQueryProto = MatchNoneQuery.newBuilder().setUnderscoreName("test_query").build();

// Call the method under test
MatchNoneQueryBuilder matchNoneQueryBuilder = MatchNoneQueryBuilderProtoUtils.fromProto(matchNoneQueryProto);
Expand All @@ -55,7 +55,7 @@ public void testFromProtoWithName() {

public void testFromProtoWithBoostAndName() {
// Create a protobuf MatchNoneQuery with boost and name
MatchNoneQuery matchNoneQueryProto = MatchNoneQuery.newBuilder().setBoost(3.0f).setName("test_query").build();
MatchNoneQuery matchNoneQueryProto = MatchNoneQuery.newBuilder().setBoost(3.0f).setUnderscoreName("test_query").build();

// Call the method under test
MatchNoneQueryBuilder matchNoneQueryBuilder = MatchNoneQueryBuilderProtoUtils.fromProto(matchNoneQueryProto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testFromProto() {
.setField("test-field")
.setValue(fieldValue)
.setBoost(2.0f)
.setName("test_query")
.setUnderscoreName("test_query")
.setCaseInsensitive(true)
.build();
QueryContainer queryContainer = QueryContainer.newBuilder().setTerm(termQuery).build();
Expand Down
Loading
Loading