Skip to content

Commit

Permalink
Fix changeQueryExpectedResultType
Browse files Browse the repository at this point in the history
Currently, we want to ensure that we return the object to the appropriate type. Previously I was just setting it to a string, but our code expects a linkedhashmap.
  • Loading branch information
Gcolon021 committed Jul 7, 2023
1 parent 3ee5d13 commit 27a35e9
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,17 @@ private String getCrossCountForQuery(QueryRequest queryRequest) throws IOExcepti

private QueryRequest changeQueryExpectedResultType(QueryRequest queryRequest) {
Object query = queryRequest.getQuery();
logger.debug("Changing query: " + query);
JsonNode jsonNode = json.valueToTree(query);
List<JsonNode> expectedResultTypeParents = jsonNode.findParents("expectedResultType");
// loop through the children of the expected result type and change the value to CROSS_COUNT. We need to use
// this approach because expectedResultType

// The reason we need to do this is that expected result type is a TextNode that is immutable.
// This is a jackson work around to replace the expectedResultType field with a new value.
for (JsonNode node : expectedResultTypeParents) {
((ObjectNode) node).put("expectedResultType", "CROSS_COUNT");
}

// Convert the jsonNode back to a string
String newQuery = jsonNode.toString();
logger.debug("Changed query: " + newQuery);

queryRequest.setQuery(newQuery);
LinkedHashMap<String, Object> rebuiltQuery = objectMapper.convertValue(jsonNode, new TypeReference<>(){});
queryRequest.setQuery(rebuiltQuery);
return queryRequest;
}

Expand Down

0 comments on commit 27a35e9

Please sign in to comment.