LuciferYang commented on code in PR #51961:
URL: https://github.com/apache/spark/pull/51961#discussion_r2265383429


##########
common/kvstore/src/test/java/org/apache/spark/util/kvstore/InMemoryStoreSuite.java:
##########
@@ -147,25 +147,25 @@ public void testRemoveAll() throws Exception {
     assertFalse(store.removeAllByIndexValues(
       ArrayKeyIndexType.class,
       KVIndex.NATURAL_INDEX_NAME,
-      ImmutableSet.of(new int[] {10, 10, 10}, new int[] { 3, 3, 3 })));
+      Set.of(new int[] {10, 10, 10}, new int[] { 3, 3, 3 })));
     assertEquals(9, store.count(ArrayKeyIndexType.class));
 
     assertTrue(store.removeAllByIndexValues(
       ArrayKeyIndexType.class,
       KVIndex.NATURAL_INDEX_NAME,
-      ImmutableSet.of(new int[] {0, 0, 0}, new int[] { 2, 2, 2 })));
+      Set.of(new int[] {0, 0, 0}, new int[] { 2, 2, 2 })));
     assertEquals(7, store.count(ArrayKeyIndexType.class));
 
     assertTrue(store.removeAllByIndexValues(
       ArrayKeyIndexType.class,
       "id",
-      ImmutableSet.of(new String [] { "things" })));
+      Set.<String[]>of(new String [] { "things" })));

Review Comment:
   ```
   Set<String> s0 = Set.of(new String[]{"1"});
   Set<String[]> s1 = Set.<String[]>of(new String[]{"1"});
   ImmutableSet<String[]> s2 = ImmutableSet.of(new String[]{"1"});
   ```
   
   Due to method overloading, there are some differences here:
   
   1. For `s0`, the following method will be called:
   
   ```
      static <E> Set<E> of(E... elements) {
           switch (elements.length) { // Implicit null check of elements
               case 0:
                   @SuppressWarnings("unchecked")
                   var set = (Set<E>) ImmutableCollections.EMPTY_SET;
                   return set;
               case 1:
                   return new ImmutableCollections.Set12<>(elements[0]);
               case 2:
                   return new ImmutableCollections.Set12<>(elements[0], 
elements[1]);
               default:
                   return new ImmutableCollections.SetN<>(elements);
           }
       }
   ```
   
   So, the result of `s0` becomes a set containing the element `"1"`.
   
   2. For `s1`, the following method will be called:
   
   ```
   static <E> Set<E> of(E e1) {
     return new ImmutableCollections.Set12<>(e1);
   }
   ```
   
   Thus, the result of `s1` becomes a set containing the array `{"1"}`.
   
   3. For `s2`, the following method will be called:
   
   ```
     public static <E> ImmutableSet<E> of(E e1) {
       return new SingletonImmutableSet<>(e1);
     }
   ```
   
   So, the result of `s2` also becomes a set containing the array `{"1"}`.
   
   Therefore, `s1` and `s2` are equivalent, while `s0` and `s2` are not 
equivalent.



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