diff --git a/paimon-common/src/main/java/org/apache/paimon/utils/Int2ShortHashMap.java b/paimon-common/src/main/java/org/apache/paimon/utils/Int2ShortHashMap.java index 0338d6d61c72..a156c8f5d154 100644 --- a/paimon-common/src/main/java/org/apache/paimon/utils/Int2ShortHashMap.java +++ b/paimon-common/src/main/java/org/apache/paimon/utils/Int2ShortHashMap.java @@ -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; } diff --git a/paimon-common/src/test/java/org/apache/paimon/utils/Int2ShortHashMapTest.java b/paimon-common/src/test/java/org/apache/paimon/utils/Int2ShortHashMapTest.java index ffd308b8e977..6fd4975eb97a 100644 --- a/paimon-common/src/test/java/org/apache/paimon/utils/Int2ShortHashMapTest.java +++ b/paimon-common/src/test/java/org/apache/paimon/utils/Int2ShortHashMapTest.java @@ -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 { @@ -53,4 +54,9 @@ public void testRandom() { assertThat(map.get(k)).isEqualTo(v); }); } + + @Test + public void testCapacity() { + assertThrows(RuntimeException.class, () -> new Int2ShortHashMap(1073741824)); + } }