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

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-chen committed May 20, 2020
1 parent 7c00be1 commit 10a76c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.Map;

/**
* Query response that encapsulates query results and isolate expression related class from formatter implementation.
* Query response that encapsulates query results and isolate {@link ExprValue} related from formatter implementation.
*/
@RequiredArgsConstructor
public class QueryResponse implements Iterable<Object[]> {
Expand Down Expand Up @@ -61,16 +61,16 @@ public Iterator<Object[]> iterator() {
}

private Map<String, ExprValue> getFirstTupleValue() {
// Assume expression is always tuple on first level and columns of all tuples are exactly same
// Assume expression is always tuple on first level
// and columns (keys) of all tuple values are exactly same
ExprValue firstValue = exprValues.iterator().next();
return ExprValueUtils.getTupleValue(firstValue);
}

private Map<String, String> populateColumnNameAndTypes(Map<String, ExprValue> tupleValue) {
Map<String, String> colNameTypes = new LinkedHashMap<>(); // Maintain original order in tuple expression
tupleValue.forEach((name, expr) -> {
colNameTypes.put(name, expr.type().name().toLowerCase());
});
// Use linked hashmap to maintain original order in tuple expression
Map<String, String> colNameTypes = new LinkedHashMap<>();
tupleValue.forEach((name, expr) -> colNameTypes.put(name, getTypeString(expr)));
return colNameTypes;
}

Expand All @@ -80,4 +80,8 @@ private Object[] convertExprValuesToValues(Collection<ExprValue> exprValues) {
toArray(Object[]::new);
}

private String getTypeString(ExprValue exprValue) {
return exprValue.type().name().toLowerCase();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static com.amazon.opendistroforelasticsearch.sql.protocol.response.format.JsonResponseFormatter.Style.PRETTY;
import static org.junit.jupiter.api.Assertions.assertEquals;

class JsonResponseFormatterTest {
class SimpleJsonResponseFormatterTest {

@Test
void formatResponse() {
Expand Down

0 comments on commit 10a76c6

Please sign in to comment.