Skip to content

Commit

Permalink
Spotless apply
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <carrofin@amazon.com>
  • Loading branch information
finnegancarroll committed Sep 23, 2024
1 parent b55d17e commit e981db7
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.search.fetch.FetchSearchResult;
import org.opensearch.proto.search.FetchSearchResultProtoDef.FetchSearchResultProto;
import org.opensearch.search.fetch.FetchSearchResult;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
import org.opensearch.core.common.text.Text;
import org.opensearch.core.index.Index;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.search.SearchShardTarget;
import org.opensearch.search.fetch.subphase.highlight.HighlightField;
import org.opensearch.proto.search.SearchHitsProtoDef.DocumentFieldProto;
import org.opensearch.proto.search.SearchHitsProtoDef.ExplanationProto;
import org.opensearch.proto.search.SearchHitsProtoDef.GenericObjectProto;
import org.opensearch.proto.search.SearchHitsProtoDef.HighlightFieldProto;
import org.opensearch.proto.search.SearchHitsProtoDef.IndexProto;
import org.opensearch.proto.search.SearchHitsProtoDef.MissingValueProto;
import org.opensearch.proto.search.SearchHitsProtoDef.SearchShardTargetProto;
import org.opensearch.proto.search.SearchHitsProtoDef.ShardIdProto;
import org.opensearch.proto.search.SearchHitsProtoDef.SortFieldProto;
import org.opensearch.proto.search.SearchHitsProtoDef.SortTypeProto;
import org.opensearch.proto.search.SearchHitsProtoDef.GenericObjectProto;
import org.opensearch.proto.search.SearchHitsProtoDef.MissingValueProto;
import org.opensearch.search.SearchShardTarget;
import org.opensearch.search.fetch.subphase.highlight.HighlightField;
import org.opensearch.transport.TransportSerializationException;

import java.io.IOException;
Expand Down Expand Up @@ -198,10 +198,7 @@ public static SortField sortFieldFromProto(SortFieldProto proto) {
field = proto.getField();
}

SortField sortField = new SortField(
field,
sortTypeFromProto(proto.getType()),
proto.getReverse());
SortField sortField = new SortField(field, sortTypeFromProto(proto.getType()), proto.getReverse());

if (proto.hasMissingValue()) {
sortField.setMissingValue(missingValueFromProto(proto.getMissingValue()));
Expand Down Expand Up @@ -235,8 +232,12 @@ public static MissingValueProto missingValueToProto(Object missingValue) {
public static Object missingValueFromProto(MissingValueProto proto) {
switch (proto.getValueCase()) {
case INT_VAL:
if (proto.getIntVal() == 1) { return SortField.STRING_FIRST; }
if (proto.getIntVal() == 2) { return SortField.STRING_LAST; }
if (proto.getIntVal() == 1) {
return SortField.STRING_FIRST;
}
if (proto.getIntVal() == 2) {
return SortField.STRING_LAST;
}
throw new TransportSerializationException("Unexpected sortField missingValue (INT_VAL): " + proto.getIntVal());
case OBJ_VAL:
return genericObjectFromProto(proto.getObjVal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.text.Text;
import org.opensearch.proto.search.SearchHitsProtoDef;
import org.opensearch.search.SearchHit;
import org.opensearch.proto.search.SearchHitsProtoDef.SearchHitProto;
import org.opensearch.proto.search.SearchHitsProtoDef.NestedIdentityProto;
import org.opensearch.proto.search.SearchHitsProtoDef.SearchHitProto;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchSortValues;
import org.opensearch.transport.TransportSerializationException;

Expand Down Expand Up @@ -77,14 +77,28 @@ SearchHitProto toProto() {
metaFields.forEach((key, value) -> builder.putMetaFields(key, documentFieldToProto(value)));
matchedQueries.forEach(builder::putMatchedQueries);

if (highlightFields != null) { highlightFields.forEach((key, value) -> builder.putHighlightFields(key, highlightFieldToProto(value))); }
if (innerHits != null) { innerHits.forEach((key, value) -> builder.putInnerHits(key, new SearchHitsProtobuf(value).toProto())); }
if (highlightFields != null) {
highlightFields.forEach((key, value) -> builder.putHighlightFields(key, highlightFieldToProto(value)));
}
if (innerHits != null) {
innerHits.forEach((key, value) -> builder.putInnerHits(key, new SearchHitsProtobuf(value).toProto()));
}

if (source != null) { builder.setSource(ByteString.copyFrom(source.toBytesRef().bytes)); }
if (id != null) { builder.setId(id.string()); }
if (nestedIdentity != null) { builder.setNestedIdentity(nestedIdentityToProto(nestedIdentity)); }
if (shard != null) { builder.setShard(searchShardTargetToProto(shard)); }
if (explanation != null) { builder.setExplanation(explanationToProto(explanation)); }
if (source != null) {
builder.setSource(ByteString.copyFrom(source.toBytesRef().bytes));
}
if (id != null) {
builder.setId(id.string());
}
if (nestedIdentity != null) {
builder.setNestedIdentity(nestedIdentityToProto(nestedIdentity));
}
if (shard != null) {
builder.setShard(searchShardTargetToProto(shard));
}
if (explanation != null) {
builder.setExplanation(explanationToProto(explanation));
}

return builder.build();
}
Expand Down Expand Up @@ -116,10 +130,10 @@ void fromProto(SearchHitProto proto) {
proto.getInnerHitsMap().forEach((key, value) -> innerHits.put(key, new SearchHitsProtobuf(value)));
}

source = proto.hasSource()? BytesReference.fromByteBuffer(proto.getSource().asReadOnlyByteBuffer()) : null;
id = proto.hasId()? new Text(proto.getId()) : null;
nestedIdentity = proto.hasNestedIdentity()? nestedIdentityFromProto(proto.getNestedIdentity()) : null;
explanation = proto.hasExplanation()? explanationFromProto(proto.getExplanation()) : null;
source = proto.hasSource() ? BytesReference.fromByteBuffer(proto.getSource().asReadOnlyByteBuffer()) : null;
id = proto.hasId() ? new Text(proto.getId()) : null;
nestedIdentity = proto.hasNestedIdentity() ? nestedIdentityFromProto(proto.getNestedIdentity()) : null;
explanation = proto.hasExplanation() ? explanationFromProto(proto.getExplanation()) : null;

if (proto.hasShard()) {
shard = searchShardTargetFromProto(proto.getShard());
Expand Down Expand Up @@ -170,7 +184,8 @@ public static SearchHitsProtoDef.SearchSortValuesProto searchSortValuesToProto(S
return builder.build();
}

public static SearchSortValues searchSortValuesFromProto(SearchHitsProtoDef.SearchSortValuesProto proto) throws TransportSerializationException {
public static SearchSortValues searchSortValuesFromProto(SearchHitsProtoDef.SearchSortValuesProto proto)
throws TransportSerializationException {
Object[] formattedSortValues = new Object[proto.getFormattedSortValuesCount()];
Object[] rawSortValues = new Object[proto.getRawSortValuesCount()];

Expand Down Expand Up @@ -209,10 +224,9 @@ public static SearchHitsProtoDef.SortValueProto sortValueToProto(Object sortValu
} else if (sortValue.getClass().equals(Boolean.class)) {
builder.setBoolValue((Boolean) sortValue);
} else if (sortValue.getClass().equals(BytesRef.class)) {
builder.setBytesValue(ByteString.copyFrom(
((BytesRef) sortValue).bytes,
((BytesRef) sortValue).offset,
((BytesRef) sortValue).length));
builder.setBytesValue(
ByteString.copyFrom(((BytesRef) sortValue).bytes, ((BytesRef) sortValue).offset, ((BytesRef) sortValue).length)
);
} else if (sortValue.getClass().equals(BigInteger.class)) {
builder.setBigIntegerValue(sortValue.toString());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
import org.apache.lucene.search.TotalHits;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchHits;
import org.opensearch.proto.search.SearchHitsProtoDef.SearchHitsProto;
import org.opensearch.proto.search.SearchHitsProtoDef.TotalHitsProto;
import org.opensearch.proto.search.SearchHitsProtoDef.SortFieldProto;
import org.opensearch.proto.search.SearchHitsProtoDef.SortValueProto;
import org.opensearch.proto.search.SearchHitsProtoDef.TotalHitsProto;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchHits;
import org.opensearch.transport.TransportSerializationException;

import java.io.IOException;
import java.util.List;

import static org.opensearch.transport.protobuf.ProtoSerDeHelpers.sortFieldToProto;
import static org.opensearch.transport.protobuf.ProtoSerDeHelpers.sortFieldFromProto;
import static org.opensearch.transport.protobuf.ProtoSerDeHelpers.sortFieldToProto;
import static org.opensearch.transport.protobuf.SearchHitProtobuf.sortValueFromProto;
import static org.opensearch.transport.protobuf.SearchHitProtobuf.sortValueToProto;

Expand Down Expand Up @@ -100,10 +100,10 @@ void fromProto(SearchHitsProto proto) throws TransportSerializationException {
hits[i] = new SearchHitProtobuf(proto.getHits(i));
}

collapseField = proto.hasCollapseField()? proto.getCollapseField() : null;
totalHits = proto.hasTotalHits()? totalHitsFromProto(proto.getTotalHits()) : null;
sortFields = proto.getSortFieldsCount() > 0? sortFieldsFromProto(proto.getSortFieldsList()) : null;
collapseValues = proto.getCollapseValuesCount() > 0? collapseValuesFromProto(proto.getCollapseValuesList()) : null;
collapseField = proto.hasCollapseField() ? proto.getCollapseField() : null;
totalHits = proto.hasTotalHits() ? totalHitsFromProto(proto.getTotalHits()) : null;
sortFields = proto.getSortFieldsCount() > 0 ? sortFieldsFromProto(proto.getSortFieldsList()) : null;
collapseValues = proto.getCollapseValuesCount() > 0 ? collapseValuesFromProto(proto.getCollapseValuesList()) : null;
}

private TotalHits totalHitsFromProto(TotalHitsProto proto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import static org.opensearch.transport.protobuf.SearchHitProtobuf.searchSortValuesToProto;

public class SearchHitProtobufTests extends AbstractWireSerializingTestCase<SearchHitProtobuf> {
public void testDocumentFieldProtoSerialization () {
public void testDocumentFieldProtoSerialization() {
DocumentField orig = randomDocumentField(randomFrom(XContentType.values()), randomBoolean(), fieldName -> false).v1();
SearchHitsProtoDef.DocumentFieldProto proto = documentFieldToProto(orig);
DocumentField cpy = documentFieldFromProto(proto);
Expand All @@ -68,7 +68,7 @@ public void testDocumentFieldProtoSerialization () {
assertNotSame(orig, cpy);
}

public void testHighlightFieldProtoSerialization () {
public void testHighlightFieldProtoSerialization() {
HighlightField orig = HighlightFieldTests.createTestItem();
SearchHitsProtoDef.HighlightFieldProto proto = highlightFieldToProto(orig);
HighlightField cpy = highlightFieldFromProto(proto);
Expand All @@ -77,7 +77,7 @@ public void testHighlightFieldProtoSerialization () {
assertNotSame(orig, cpy);
}

public void testSearchSortValuesProtoSerialization () {
public void testSearchSortValuesProtoSerialization() {
SearchSortValues orig = SearchSortValuesTests.createTestItem(randomFrom(XContentType.values()), true);
SearchHitsProtoDef.SearchSortValuesProto proto = searchSortValuesToProto(orig);
SearchSortValues cpy = searchSortValuesFromProto(proto);
Expand All @@ -86,7 +86,7 @@ public void testSearchSortValuesProtoSerialization () {
assertNotSame(orig, cpy);
}

public void testNestedIdentityProtoSerialization () {
public void testNestedIdentityProtoSerialization() {
SearchHit.NestedIdentity orig = NestedIdentityTests.createTestItem(randomIntBetween(0, 2));
SearchHitsProtoDef.NestedIdentityProto proto = SearchHitProtobuf.nestedIdentityToProto(orig);
SearchHit.NestedIdentity cpy = SearchHitProtobuf.nestedIdentityFromProto(proto);
Expand All @@ -95,7 +95,7 @@ public void testNestedIdentityProtoSerialization () {
assertNotSame(orig, cpy);
}

public void testSearchShardTargetProtoSerialization () {
public void testSearchShardTargetProtoSerialization() {
String index = randomAlphaOfLengthBetween(5, 10);
String clusterAlias = randomBoolean() ? null : randomAlphaOfLengthBetween(5, 10);
SearchShardTarget orig = new SearchShardTarget(
Expand All @@ -111,7 +111,7 @@ public void testSearchShardTargetProtoSerialization () {
assertNotSame(orig, cpy);
}

public void testExplanationProtoSerialization () {
public void testExplanationProtoSerialization() {
Explanation orig = createExplanation(randomIntBetween(0, 5));
SearchHitsProtoDef.ExplanationProto proto = explanationToProto(orig);
Explanation cpy = explanationFromProto(proto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import static org.opensearch.transport.protobuf.SearchHitProtobuf.sortValueToProto;

public class SearchHitsProtobufTests extends AbstractWireSerializingTestCase<SearchHitsProtobuf> {
public void testSortFieldProtoSerialization () {
public void testSortFieldProtoSerialization() {
SortField[] fields = SearchHitsTests.createSortFields(randomIntBetween(1, 5));
for (SortField orig : fields) {
SearchHitsProtoDef.SortFieldProto proto = sortFieldToProto(orig);
Expand All @@ -56,7 +56,7 @@ public void testSortFieldProtoSerialization () {
}
}

public void testSortValueProtoSerialization () {
public void testSortValueProtoSerialization() {
Object[] values = SearchHitsTests.createCollapseValues(randomIntBetween(1, 10));
for (Object orig : values) {
SearchHitsProtoDef.SortValueProto proto = sortValueToProto(orig);
Expand Down

0 comments on commit e981db7

Please sign in to comment.