leventov commented on a change in pull request #8157: Enum of ResponseContext keys URL: https://github.com/apache/incubator-druid/pull/8157#discussion_r310214601
########## File path: processing/src/main/java/org/apache/druid/query/context/ResponseContext.java ########## @@ -342,26 +348,22 @@ public SerializationResult serializeWith(ObjectMapper objectMapper, int maxChars final JsonNode node = e.getValue(); if (node.isArray()) { if (needToRemoveCharsNumber >= node.toString().length()) { - final int lengthBeforeRemove = node.toString().length(); - // Empty array could be correctly deserialized so we remove only its elements. - ((ArrayNode) node).removeAll(); - final int lengthAfterRemove = node.toString().length(); - needToRemoveCharsNumber -= lengthBeforeRemove - lengthAfterRemove; + // We need to remove more chars than the field's lenght so removing it completely + contextJsonNode.remove(fieldName); + // Since the field is completely removed (name + value) we need to do a recalculation + needToRemoveCharsNumber = contextJsonNode.toString().length() - maxCharsNumber; } else { - final ArrayNode arrNode = (ArrayNode) node; - while (node.size() > 0 && needToRemoveCharsNumber > 0) { - final int lengthBeforeRemove = arrNode.toString().length(); - // Reducing complexity by removing half of array's elements - final int removeUntil = node.size() / 2; - for (int removeAt = node.size() - 1; removeAt >= removeUntil; removeAt--) { - arrNode.remove(removeAt); - } - final int lengthAfterRemove = arrNode.toString().length(); - needToRemoveCharsNumber -= lengthBeforeRemove - lengthAfterRemove; + final ArrayNode arrayNode = (ArrayNode) node; + needToRemoveCharsNumber -= removeNodeElementsToSatisfyCharsLimit(arrayNode, needToRemoveCharsNumber); + if (arrayNode.size() == 0) { + // The field is empty, removing it. Review comment: Please extend the comment like `The field is empty, removing it because an empty array field may be misleading for the recipients of the truncated response context.` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org