Skip to content

Commit 897c628

Browse files
committed
Require positive maxPartitions in CoalescedRDD
1 parent 351a36d commit 897c628

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

core/src/main/scala/org/apache/spark/rdd/CoalescedRDD.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private[spark] case class CoalescedRDDPartition(
6969
* the preferred location of each new partition overlaps with as many preferred locations of its
7070
* parent partitions
7171
* @param prev RDD to be coalesced
72-
* @param maxPartitions number of desired partitions in the coalesced RDD
72+
* @param maxPartitions number of desired partitions in the coalesced RDD (must be positive)
7373
* @param balanceSlack used to trade-off balance and locality. 1.0 is all locality, 0 is all balance
7474
*/
7575
private[spark] class CoalescedRDD[T: ClassTag](
@@ -78,6 +78,10 @@ private[spark] class CoalescedRDD[T: ClassTag](
7878
balanceSlack: Double = 0.10)
7979
extends RDD[T](prev.context, Nil) { // Nil since we implement getDependencies
8080

81+
if (maxPartitions < 1) {
82+
throw new IllegalArgumentException(s"Number of partitions ($maxPartitions) must be positive.")
83+
}
84+
8185
override def getPartitions: Array[Partition] = {
8286
val pc = new PartitionCoalescer(maxPartitions, prev, balanceSlack)
8387

0 commit comments

Comments
 (0)