jiajunwang commented on a change in pull request #1256:
URL: https://github.com/apache/helix/pull/1256#discussion_r469427895



##########
File path: 
helix-core/src/main/java/org/apache/helix/controller/changedetector/trimmer/HelixPropertyTrimmer.java
##########
@@ -57,38 +57,49 @@
    * @param originalProperty
    */
   protected ZNRecord doTrim(T originalProperty) {
+    ZNRecord originalZNRecord = originalProperty.getRecord();
     ZNRecord trimmedZNRecord = new ZNRecord(originalProperty.getId());
-    for (Map.Entry<FieldType, Set<String>> fieldEntry : getNonTrimmableFields(
-        originalProperty).entrySet()) {
+    Map<FieldType, Set<String>> nonTrimmableFields = 
getNonTrimmableFields(originalProperty);
+
+    // Ensure the keys of all map fields and list fields are preserved even 
after the trim.
+    // The keys of list and map fields are relatively stable and contain 
important information. So
+    // they should not be trimmed.
+    originalZNRecord.getMapFields().keySet().stream()
+        .forEach(key -> trimmedZNRecord.setMapField(key, 
Collections.EMPTY_MAP));
+    originalZNRecord.getListFields().keySet().stream()
+        .forEach(key -> trimmedZNRecord.setListField(key, 
Collections.EMPTY_LIST));

Review comment:
       Good idea. It helps to clean up the code.




----------------------------------------------------------------
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]



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

Reply via email to