Github user mengxr commented on a diff in the pull request: https://github.com/apache/spark/pull/916#discussion_r13691153 --- Diff: core/src/main/scala/org/apache/spark/rdd/RDD.scala --- @@ -394,20 +401,22 @@ abstract class RDD[T: ClassTag]( return new Array[T](0) } - if (initialCount > Integer.MAX_VALUE - 1) { - maxSelected = Integer.MAX_VALUE - 1 - } else { - maxSelected = initialCount.toInt + if (!withReplacement && num > initialCount) { + throw new IllegalArgumentException("Cannot create sample larger than the original when " + + "sampling without replacement") } - if (num > initialCount && !withReplacement) { - total = maxSelected - fraction = multiplier * (maxSelected + 1) / initialCount - } else { - fraction = multiplier * (num + 1) / initialCount - total = num + if (initialCount > Integer.MAX_VALUE - 1) { + val maxSelected = Integer.MAX_VALUE - (5.0 * math.sqrt(Integer.MAX_VALUE)).toInt + if (num > maxSelected) { + throw new IllegalArgumentException("Cannot support a sample size > Integer.MAX_VALUE - " + + "5.0 * math.sqrt(Integer.MAX_VALUE)") + } } + fraction = SamplingUtils.computeFraction(num, initialCount, withReplacement) --- End diff -- `fraction` could be a `val`.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---