Skip to content

Commit

Permalink
Fix SearchSourceBuilder read/write test failures
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com>
  • Loading branch information
deshsidd committed Jul 16, 2024
1 parent 999b779 commit 6b925be
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.tasks.resourcetracker.TaskResourceInfo;
import org.opensearch.search.builder.SearchSourceBuilder;

import java.io.IOException;
import java.util.Collections;
Expand Down Expand Up @@ -90,6 +91,8 @@ static void writeTo(final StreamOutput out, final Attribute attribute) throws IO
public static void writeValueTo(StreamOutput out, Object attributeValue) throws IOException {
if (attributeValue instanceof List) {
out.writeList((List<? extends Writeable>) attributeValue);
} else if (attributeValue instanceof SearchSourceBuilder) {
((SearchSourceBuilder) attributeValue).writeTo(out);
} else {
out.writeGenericValue(attributeValue);
}
Expand All @@ -106,6 +109,9 @@ public static void writeValueTo(StreamOutput out, Object attributeValue) throws
public static Object readAttributeValue(StreamInput in, Attribute attribute) throws IOException {
if (attribute == Attribute.TASK_RESOURCE_USAGES) {
return in.readList(TaskResourceInfo::readFromStream);
} else if (attribute == Attribute.SOURCE) {
SearchSourceBuilder builder = new SearchSourceBuilder(in);
return builder;
} else {
return in.readGenericValue();
}
Expand Down

0 comments on commit 6b925be

Please sign in to comment.