diff --git a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/AggregateFunction.java b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/AggregateFunction.java index dac1445426..ee8fdaf3b7 100644 --- a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/AggregateFunction.java +++ b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/ast/expression/AggregateFunction.java @@ -16,6 +16,7 @@ package com.amazon.opendistroforelasticsearch.sql.ast.expression; import com.amazon.opendistroforelasticsearch.sql.ast.AbstractNodeVisitor; +import com.amazon.opendistroforelasticsearch.sql.common.utils.StringUtils; import java.util.Collections; import java.util.List; import lombok.EqualsAndHashCode; @@ -57,6 +58,6 @@ public R accept(AbstractNodeVisitor nodeVisitor, C context) { @Override public String toString() { - return String.format("%s(%s)", funcName, field); + return StringUtils.format("%s(%s)", funcName, field); } } diff --git a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTupleValue.java b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTupleValue.java index 41c702a255..fb8cd658a5 100644 --- a/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTupleValue.java +++ b/core/src/main/java/com/amazon/opendistroforelasticsearch/sql/data/model/ExprTupleValue.java @@ -42,7 +42,11 @@ public static ExprTupleValue fromExprValueMap(Map map) { @Override public Object value() { - return valueMap; + LinkedHashMap resultMap = new LinkedHashMap<>(); + for (Entry entry : valueMap.entrySet()) { + resultMap.put(entry.getKey(), entry.getValue().value()); + } + return resultMap; } @Override diff --git a/elasticsearch/src/test/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/value/ElasticsearchExprValueFactoryTest.java b/elasticsearch/src/test/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/value/ElasticsearchExprValueFactoryTest.java index 1a4cb83a6d..5fb4ff2946 100644 --- a/elasticsearch/src/test/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/value/ElasticsearchExprValueFactoryTest.java +++ b/elasticsearch/src/test/java/com/amazon/opendistroforelasticsearch/sql/elasticsearch/data/value/ElasticsearchExprValueFactoryTest.java @@ -272,7 +272,7 @@ public void constructUnsupportedTypeThrowException() { } public Map tupleValue(String jsonString) { - return (Map) exprValueFactory.construct(jsonString).value(); + return exprValueFactory.construct(jsonString).tupleValue(); } private ExprValue constructFromObject(String fieldName, Object value) { diff --git a/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/unittest/planner/QueryPlannerTest.java b/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/unittest/planner/QueryPlannerTest.java index c334d43057..33c818b4b2 100644 --- a/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/unittest/planner/QueryPlannerTest.java +++ b/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/unittest/planner/QueryPlannerTest.java @@ -23,6 +23,7 @@ import com.amazon.opendistroforelasticsearch.sql.legacy.domain.JoinSelect; import com.amazon.opendistroforelasticsearch.sql.legacy.esdomain.LocalClusterState; import com.amazon.opendistroforelasticsearch.sql.legacy.exception.SqlParseException; +import com.amazon.opendistroforelasticsearch.sql.legacy.metrics.Metrics; import com.amazon.opendistroforelasticsearch.sql.legacy.parser.ElasticSqlExprParser; import com.amazon.opendistroforelasticsearch.sql.legacy.parser.SqlParser; import com.amazon.opendistroforelasticsearch.sql.legacy.plugin.SqlSettings; @@ -140,6 +141,8 @@ public SearchResponse answer(InvocationOnMock invocation) { returnMockResponse(SCROLL_ID1, response1); returnMockResponse(SCROLL_ID2, response2); + + Metrics.getInstance().registerDefaultMetrics(); } private void returnMockResponse(String scrollId, SearchResponse response) { diff --git a/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java b/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java index 6cb9d6c85f..f29937fad3 100644 --- a/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java +++ b/protocol/src/test/java/com/amazon/opendistroforelasticsearch/sql/protocol/response/format/SimpleJsonResponseFormatterTest.java @@ -109,6 +109,27 @@ void formatResponseWithMissingValue() { formatter.format(response)); } + @Test + void formatResponseWithTupleValue() { + QueryResult response = + new QueryResult( + schema, + Arrays.asList( + tupleValue(ImmutableMap + .of("name", "Smith", + "address", ImmutableMap.of("state", "WA", "street", + ImmutableMap.of("city", "seattle")))))); + SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT); + + assertEquals( + "{\"schema\":[{\"name\":\"firstname\",\"type\":\"string\"}," + + "{\"name\":\"age\",\"type\":\"integer\"}]," + + "\"datarows\":[[\"Smith\",{\"state\":\"WA\",\"street\":{\"city\":\"seattle\"}}]]," + + "\"total\":1,\"size\":1}", + formatter.format(response)); + } + + @Test void formatError() { SimpleJsonResponseFormatter formatter = new SimpleJsonResponseFormatter(COMPACT);