Skip to content

Commit d5e3df8

Browse files
committed
Require positive number of partitions in HashPartitioner
1 parent 897c628 commit d5e3df8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

core/src/main/scala/org/apache/spark/Partitioner.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ object Partitioner {
7676
* produce an unexpected or incorrect result.
7777
*/
7878
class HashPartitioner(partitions: Int) extends Partitioner {
79+
if (partitions < 1) {
80+
throw new IllegalArgumentException(s"Number of partitions ($partitions) must be positive.")
81+
}
82+
7983
def numPartitions: Int = partitions
8084

8185
def getPartition(key: Any): Int = key match {

0 commit comments

Comments
 (0)