surekhasaharan commented on a change in pull request #8059: Refactoring to use 
`CollectionUtils.mapValues`
URL: https://github.com/apache/incubator-druid/pull/8059#discussion_r304007145
 
 

 ##########
 File path: core/src/main/java/org/apache/druid/utils/CollectionUtils.java
 ##########
 @@ -88,12 +89,22 @@ public int size()
 
   /**
    * Returns a transformed map from the given input map where the key is 
modified based on the given keyMapper
-   * function.
+   * function. This method fails if keys collide after applying the  given 
keyMapper function and
+   * throws a IllegalStateException.
+   *
+   * @throws ISE if key collisions occur while applying specified keyMapper
    */
+
   public static <K, V, K2> Map<K2, V> mapKeys(Map<K, V> map, Function<K, K2> 
keyMapper)
   {
     final Map<K2, V> result = Maps.newHashMapWithExpectedSize(map.size());
-    map.forEach((k, v) -> result.put(keyMapper.apply(k), v));
+    map.forEach((k, v) -> {
+      final K2 k2 = keyMapper.apply(k);
+      if (result.containsKey(k2)) {
 
 Review comment:
   i see, fixed.

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

Reply via email to