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

Commit

Permalink
Fix ExprCollectionValue serialization bug (#859)
Browse files Browse the repository at this point in the history
* fix expr array value json

* update
  • Loading branch information
penghuo authored Nov 26, 2020
1 parent 200a76d commit 2773bc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
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

0 comments on commit 2773bc3

Please sign in to comment.