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

Fix bug of nested field format issue in JDBC response #846

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 @@ -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;
Expand Down Expand Up @@ -57,6 +58,6 @@ public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) {

@Override
public String toString() {
return String.format("%s(%s)", funcName, field);
return StringUtils.format("%s(%s)", funcName, field);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public static ExprTupleValue fromExprValueMap(Map<String, ExprValue> map) {

@Override
public Object value() {
return valueMap;
LinkedHashMap<String, Object> resultMap = new LinkedHashMap<>();
for (Entry<String, ExprValue> entry : valueMap.entrySet()) {
resultMap.put(entry.getKey(), entry.getValue().value());
}
return resultMap;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void constructUnsupportedTypeThrowException() {
}

public Map<String, ExprValue> tupleValue(String jsonString) {
return (Map<String, ExprValue>) exprValueFactory.construct(jsonString).value();
return exprValueFactory.construct(jsonString).tupleValue();
}

private ExprValue constructFromObject(String fieldName, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down