Skip to content

Commit

Permalink
[core] Fix HashBucketAssigner load index too large error with refacto…
Browse files Browse the repository at this point in the history
…r exception (#3796)
  • Loading branch information
xuzifu666 authored Aug 7, 2024
1 parent 06cbee0 commit 12c4684
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ public void put(int key, short value) {
}

public Int2ShortHashMap build() {
Int2ShortHashMap map = new Int2ShortHashMap(keyList.size());
for (int i = 0; i < keyList.size(); i++) {
map.put(keyList.getInt(i), valueList.getShort(i));
Int2ShortHashMap map;
try {
map = new Int2ShortHashMap(keyList.size());
for (int i = 0; i < keyList.size(); i++) {
map.put(keyList.getInt(i), valueList.getShort(i));
}
} catch (IllegalArgumentException e) {
throw new RuntimeException(
"capacity of Int2ShortOpenHashMap is too large, advise raise your parallelism in your Flink/Spark job",
e);
}
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Random;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

/** Test for {@link Int2ShortHashMap}. */
public class Int2ShortHashMapTest {
Expand Down Expand Up @@ -53,4 +54,9 @@ public void testRandom() {
assertThat(map.get(k)).isEqualTo(v);
});
}

@Test
public void testCapacity() {
assertThrows(RuntimeException.class, () -> new Int2ShortHashMap(1073741824));
}
}

0 comments on commit 12c4684

Please sign in to comment.