Skip to content

Commit a40e8fb

Browse files
committed
replace if with require
1 parent ad483fd commit a40e8fb

File tree

1 file changed

+2
-3
lines changed
  • core/src/main/scala/org/apache/spark/rdd

1 file changed

+2
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,8 @@ abstract class RDD[T: ClassTag](
310310
* Return a sampled subset of this RDD.
311311
*/
312312
def sample(withReplacement: Boolean, fraction: Double, seed: Int): RDD[T] = {
313-
if (fraction < Double.MinValue || fraction > Double.MaxValue) {
314-
throw new Exception("Invalid fraction value:" + fraction)
315-
}
313+
require(fraction >= 0 && fraction <= Double.MaxValue,
314+
"Invalid fraction value: " + fraction)
316315
if (withReplacement) {
317316
new PartitionwiseSampledRDD[T, T](this, new PoissonSampler[T](fraction), seed)
318317
} else {

0 commit comments

Comments
 (0)