vrajat commented on code in PR #13816:
URL: https://github.com/apache/pinot/pull/13816#discussion_r1716420580


##########
pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/utils/BrokerSelectorUtils.java:
##########
@@ -57,11 +59,13 @@ public static List<String> 
getTablesCommonBrokers(List<String> tableNames, Map<S
       return null;
     }
 
-    List<String> commonBrokers = tablesBrokersList.get(0);
-    for (int i = 1; i < tablesBrokersList.size(); i++) {
-      commonBrokers.retainAll(tablesBrokersList.get(i));
-    }
-    return commonBrokers;
+    // Make a copy of the brokersList for the first table. retainAll does 
inplace modifications corrupting brokerData.
+    Set<String> commonBrokers = tablesBrokersList.stream()
+        .skip(1) // skip because the HashSet is initialized with the first 
list.
+        .collect(() -> new HashSet<>(tablesBrokersList.get(0)), 
Set::retainAll, Set::retainAll);
+    List<String> commonBrokerList = new ArrayList<>(commonBrokers.size());
+    commonBrokerList.addAll(commonBrokers);
+    return commonBrokerList;

Review Comment:
   Done. In terms of efficiency, Set vs List doesnt matter as the size of the 
list is small. So moved back to list.



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

To unsubscribe, e-mail: [email protected]

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