esevastyanov commented on a change in pull request #8157: Enum of 
ResponseContext keys
URL: https://github.com/apache/incubator-druid/pull/8157#discussion_r310223983
 
 

 ##########
 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:
   Extended

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to