Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix ExprCollectionValue serialization bug #859

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import com.amazon.opendistroforelasticsearch.sql.data.type.ExprCoreType;
import com.amazon.opendistroforelasticsearch.sql.data.type.ExprType;
import com.google.common.base.Objects;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;

/**
Expand All @@ -34,7 +33,11 @@ public class ExprCollectionValue extends AbstractExprValue {

@Override
public Object value() {
return valueList;
List<Object> results = new ArrayList<>();
for (ExprValue exprValue : valueList) {
results.add(exprValue.value());
}
return results;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ void formatResponseWithTupleValue() {
formatter.format(response));
}

@Test
void formatResponseWithArrayValue() {
QueryResult response =
new QueryResult(
schema,
Arrays.asList(
tupleValue(ImmutableMap
.of("name", "Smith",
"address", Arrays.asList(
ImmutableMap.of("state", "WA"), ImmutableMap.of("state", "NYC")
)))));
SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT);
assertEquals(
"{\"schema\":[{\"name\":\"firstname\",\"type\":\"string\"},"
+ "{\"name\":\"age\",\"type\":\"integer\"}],"
+ "\"datarows\":[[\"Smith\",[{\"state\":\"WA\"},{\"state\":\"NYC\"}]]],"
+ "\"total\":1,\"size\":1}",
formatter.format(response));
}

@Test
void formatError() {
Expand Down